playMaker

Author Topic: How to rotate the First Person in Unity 5?  (Read 7610 times)

NvdS

  • Playmaker Newbie
  • *
  • Posts: 18
How to rotate the First Person in Unity 5?
« on: August 25, 2015, 07:36:32 AM »
Hi,

I made a menu (unity 5) to teletransport my FPSController. Basically this is what happens:

- I use empty game objects with a get rotation and get position action on it to store different locations. Values are stored in a global variable.
- Activate a menu by pressing space.
- Menu opens and character controller is disabled to 'freeze' the camera (set time scale to 0 doesn't freeze the camera, just the movement?)
- Press a button to set the rotation and position of the FPSController.

So far it works. When I press the button the FPSController does move correctly, both position and rotation. But when I enable the character controller again the rotation value of the FPSController is set to the value it had when the controller was disabled. The position is set correctly.

I've tried to set position and rotation without disabling the character controller and the same issue occurs. The rotation isn't set to the value stored in the global variable. I also tried to apply the same script to a cube instead of the FPSController. That one worked perfectly, so it seems that it's not possible to set the rotation of the FPSController???

It seems to be a conflict with the Mouse Look section of the First Person Controller Script but really...I don't get it exactly...Does anyone have a clue what goes wrong here? And what to do?
« Last Edit: August 26, 2015, 08:00:21 AM by NvdS »

Grendal

  • Playmaker Newbie
  • *
  • Posts: 31
Re: How to rotate the First Person in Unity 5?
« Reply #1 on: August 27, 2015, 11:21:31 PM »
Have you tried parenting the controller object to an empty gameobject that you perform the rotation/position on?

Also you say you save position/rotation data after disabling the controller object?
Try storing it before disabling the object.
« Last Edit: August 27, 2015, 11:28:12 PM by Grendal »

NvdS

  • Playmaker Newbie
  • *
  • Posts: 18
Re: How to rotate the First Person in Unity 5?
« Reply #2 on: August 28, 2015, 03:54:46 AM »
Thanks for thinking along with me Grendal!

Have you tried parenting the controller object to an empty gameobject that you perform the rotation/position on?

I didn't think of this option but it didn't work. Intentionally it did, it set the rotation of the game object and FPScontr. right. When you start walking again and you teletransport to the same spot again it doesn't reset the rotation because the game object is already set to that rotation...As soon as you reset the rotation of the game object to 0.0.0 again it flips...

Also you say you save position/rotation data after disabling the controller object?
Try storing it before disabling the object.

this is kind of the problem. It's not possible to set/store the rotation of the FPSContr. with the controller script enabled.

I did work on a workaround though. It's still not 100% right, but in general it works:

- I removed all of the mouse look parts from the FirstPersonController.cs in MonoDevelop (script is attached)
- Then I added a simple FSM with only a mouse look action to the FPS Controller
- When I open the teletransport menu I disable this FSM
- Teletransporting works right now and when I close the menu I enable the FSM again

This workaround kind of confirmed that the issue is caused by the 'mouse look section' in the FirstPersonController script. In previous Unity versions this used to be a separate script...I don't know why they merged it with the controller script.

But since I'm a newnewnewbe to scripting I'm still eager to hear other thoughts on this one! There might be a more simple solution...

terri

  • Sr. Member
  • ****
  • Posts: 386
    • terrivellmann.tumblr.com
Re: How to rotate the First Person in Unity 5?
« Reply #3 on: August 28, 2015, 08:59:34 AM »
The controller's mouselook probably overrides any rotation you're setting. The controller's rotation and the camera rotation will be two different things.

Not sure how you would fix it, but personally I like building the controllers from scratch so you actually know how things work.

NvdS

  • Playmaker Newbie
  • *
  • Posts: 18
Re: How to rotate the First Person in Unity 5?
« Reply #4 on: September 01, 2015, 03:40:24 AM »
I'm pretty sure that's the thing Terri...

Possibly building a controller from scratch is the solution but I don't really know how to fix that. I found some basic's but these threads/tut's are really old. Maybe you can share your example?

I tend to stick to the one provided to unity since it also has VR support.

As I mentioned in a previous post I kind of found a workaround although it's not a 100% solid solution yet...

terri

  • Sr. Member
  • ****
  • Posts: 386
    • terrivellmann.tumblr.com
Re: How to rotate the First Person in Unity 5?
« Reply #5 on: September 01, 2015, 11:38:07 AM »
There are different ways to do it, depending on what you need.
Here's a basic one

Capsule collider with character controller.
FSMs on the capsule:
Get Axis Vector -> Controller Simple Move
Mouse Look (mouse x)

Camera is parented to the character controller.
FSM on camera:
Mouse Look (mouse y)

Of course if you want to jump, crouch, etc you'll need to work that in, but in my opinion that's what you're signing up for when you want to make a game