Playmaker Forum

PlayMaker Help & Tips => PlayMaker Tips & Tricks => Topic started by: Alex Chouls on April 03, 2011, 12:52:14 PM

Title: Making a First Person Controller
Post by: Alex Chouls on April 03, 2011, 12:52:14 PM
Somebody asked about making a first person controller in Playmaker on the Unity forums, so I thought I'd reproduce the answer here:

Note, if the standard first person controller in Unity works for you there's no need to reinvent the wheel! But this might still be interesting as an example of how to use Get Axis and Transform actions...

A simple first person controller made with actions (thrown together in 5 minutes):

(http://www.hutonggames.com/docs/img/firstPersonController.png)

Put this on a capsule with a Character Controller component and an attached camera (similar to the setup for the built-in Unity first person controller).

In practice I'd probably split the movement and mouselook into 2 FSMs so they can have their own states. (e.g. Lock movement, but still look around; or take control over the camera to lock onto a target etc.).

Also you should limit the tilt, and use variables for move/pan/tilt speeds so you can expose them in the FSM Inspector and have a nice front end for your controller (Move Speed, Pan Speed, Tilt Speed, Max Tilt...).

When I have a moment I'll try to wrap this up into a nice sample and template.
Title: Re: Making a First Person Controller
Post by: tobbeo on April 04, 2011, 06:53:30 PM
Thanks for the example :) Straight forward and makes sense.
Title: Re: Making a First Person Controller
Post by: Steamgauge on April 06, 2011, 08:09:29 AM
Very useful information, thank you!
Title: Re: Making a First Person Controller
Post by: dotty on April 11, 2011, 12:05:39 PM
Any idea's how to make the head movement faster? Seems slow.
Title: Re: Making a First Person Controller
Post by: MaDDoX on April 11, 2011, 08:07:47 PM
Have you tried playing with the "multiplier" fields in the "Get Axis" actions?
Title: Re: Making a First Person Controller
Post by: dotty on April 12, 2011, 06:56:13 AM
yeah, but it seems to mess up the rotation.
Title: Re: Making a First Person Controller
Post by: MaDDoX on April 12, 2011, 04:40:17 PM
yeah, but it seems to mess up the rotation.
Hmm, maybe the "multiplier" inside GetAxis isn't as obvious as it sounds. Try performing a math/multiply action on the 'pan' and 'tilt' variable before finally assigning them to the rotate actions.
Title: Re: Making a First Person Controller
Post by: Alex Chouls on April 12, 2011, 05:28:39 PM
The multiplier should work... are you limiting tilt? If you increase the tilt multiplier it would be very easy to tilt past 90 and reverse the controls - maybe that is what you're seeing? Or maybe there's a bug.

I want to add limits to the Rotate action, but for now you can use GetRotation, ClampFloat, and SetRotation (kind of ugly... should be simpler!)
Title: Re: Making a First Person Controller
Post by: dotty on April 13, 2011, 03:18:12 AM
I'm seeing the inverted camera bug. Could you provide a screenshot of what you think the solution is please.
Title: Re: Making a First Person Controller
Post by: Tinker on April 21, 2012, 11:55:50 PM
If I may add,

I want to make the character jump using the "Add Force" since it has a rigid body.

Because this method is dependent on the Character Controller, the character controller overrides the "Add Force" and ignores it even though the FSM works as it should.

How would you go about fixing the jumping problem without having to use the Character Motor script?

-Tinker
Title: Re: Making a First Person Controller
Post by: Deadlyapples666 on April 22, 2012, 10:21:07 AM
I wana know this too :O
Title: Re: Making a First Person Controller
Post by: jeanfabre on April 22, 2012, 05:34:25 PM
hi,

 Stay tuned, I am almost done with porting M2h jump game, totally in playmaker and it uses addForce to make the player jump and jump,

 you can get his examples from the asset store already ( you'll need it anyway): http://u3d.as/content/m2h/c-game-examples/1sG (http://u3d.as/content/m2h/c-game-examples/1sG)

You can check out the games I have already ported:

https://hutonggames.fogbugz.com/default.asp?W880 (https://hutonggames.fogbugz.com/default.asp?W880)

 Bye,

 Jean
Title: Re: Making a First Person Controller
Post by: Tinker on April 23, 2012, 03:22:10 PM
The multiplier should work... are you limiting tilt? If you increase the tilt multiplier it would be very easy to tilt past 90 and reverse the controls - maybe that is what you're seeing? Or maybe there's a bug.

I want to add limits to the Rotate action, but for now you can use GetRotation, ClampFloat, and SetRotation (kind of ugly... should be simpler!)

I'v spent hours trying to figure out how to clamp the rotation but its becoming very frustrating.

When tilting on run time, the  rotation returns 0 when camera faces forward (camera faces horizon).
If you move the mouse to look upwards, the camera's rotation changes from 0 to 360 and decrease as the camera continues to face upward, if the camera faces downwards, the 0 raises to 90 and decreases back to 0 inverted.

Can somebody post a solution to this? I can't seem to figure how to fix this.

- Tinker
Title: Re: Making a First Person Controller
Post by: FractalCore on May 11, 2012, 12:22:29 AM
I struggled with this for ages too. Then noticed a mouselook action had been added. Which comes with limits. So this example might be a little out of date. Though still useful to learn.
Title: Re: Making a First Person Controller
Post by: J1RG on November 16, 2013, 10:25:07 PM
The multiplier should work... are you limiting tilt? If you increase the tilt multiplier it would be very easy to tilt past 90 and reverse the controls - maybe that is what you're seeing? Or maybe there's a bug.

I want to add limits to the Rotate action, but for now you can use GetRotation, ClampFloat, and SetRotation (kind of ugly... should be simpler!)

I'v spent hours trying to figure out how to clamp the rotation but its becoming very frustrating.

When tilting on run time, the  rotation returns 0 when camera faces forward (camera faces horizon).
If you move the mouse to look upwards, the camera's rotation changes from 0 to 360 and decrease as the camera continues to face upward, if the camera faces downwards, the 0 raises to 90 and decreases back to 0 inverted.

Can somebody post a solution to this? I can't seem to figure how to fix this.

- Tinker

Sorry for necroing this thread but I could use help with this as well. Although I am using shift+WASD keyboard look controls. Any suggestions for setting up a Float Clamp that should theoretically be min: -60 max: 60 but the camera won't tilt to it in the appropriate 360 to 300 degrees?
Title: Re: Making a First Person Controller
Post by: jeanfabre on November 18, 2013, 02:18:19 AM
Hi,

 You may encounter some gimbal lock here.

Are you clamping absolute values? if so, I would suggest doing it otherwise:

maintain a float that represents the angle since the default position. As you tilt you add the delta rotation to this angle, and you check that this angle is between 60 and -60 and if not you don't rotate, else you rotate.

 this way you can rotate safely your camera withotu gimbal lock and you use a safe way to detect limits, withotu relying on angles passing the 360 range and falling back to 0 etc etc.

bye,

 Jean
Title: Re: Making a First Person Controller
Post by: gheeDough on December 01, 2013, 05:59:45 PM
Any chance of doing the same for a 2D character controller?? I'm struggling...  ::)
Title: Re: Making a First Person Controller
Post by: jeanfabre on December 02, 2013, 02:39:04 AM
Hi,

 yes, this is coming soon with the Unity 2d platform port to PlayMaker.

bye,

 Jean
Title: Re: Making a First Person Controller
Post by: gheeDough on December 13, 2013, 05:28:35 AM
Awesome, thanks!  ;D
Title: Re: Making a First Person Controller
Post by: JonathanBurroughs on March 26, 2014, 08:46:24 AM
Indirectly this has proved super useful in finding a way to trigger turn animations on my player character. Just using Get Axis on the X Mouse input to drive an Animator Controller Float. Boom! Thank you guys so much.
Title: Re: Making a First Person Controller
Post by: coffeeANDsoda on September 07, 2014, 11:12:42 PM
Somebody asked about making a first person controller in Playmaker on the Unity forums, so I thought I'd reproduce the answer here:

Note, if the standard first person controller in Unity works for you there's no need to reinvent the wheel! But this might still be interesting as an example of how to use Get Axis and Transform actions...

A simple first person controller made with actions (thrown together in 5 minutes):

(http://www.onigirl.com/hutongGames/docs/img/firstPersonController.png)

Put this on a capsule with a Character Controller component and an attached camera (similar to the setup for the built-in Unity first person controller).

In practice I'd probably split the movement and mouselook into 2 FSMs so they can have their own states. (e.g. Lock movement, but still look around; or take control over the camera to lock onto a target etc.).

Also you should limit the tilt, and use variables for move/pan/tilt speeds so you can expose them in the FSM Inspector and have a nice front end for your controller (Move Speed, Pan Speed, Tilt Speed, Max Tilt...).

When I have a moment I'll try to wrap this up into a nice sample and template.

Old thread but I've wondered how a person would make one without using the standard premade FPconrtoller script.
Title: Re: Making a First Person Controller
Post by: C.J.Geringer on December 09, 2014, 06:01:36 PM
I can´t see the example in the first post for some reason, anyone else have the same problem?
Title: Re: Making a First Person Controller
Post by: coffeeANDsoda on January 08, 2015, 06:00:57 PM
I can´t see the example in the first post for some reason, anyone else have the same problem?

Me to, I'd just like to see a video tutorial or pics for reference.
Title: Re: Making a First Person Controller
Post by: jeanfabre on January 13, 2015, 02:54:05 AM
Hi,

 uhm, yes odd, I have contacted Alex on this, he will be able to track this.

 Bye,

 Jean
Title: Re: Making a First Person Controller
Post by: coffeeANDsoda on January 13, 2015, 03:04:06 AM
Hi,

 uhm, yes odd, I have contacted Alex on this, he will be able to track this.

 Bye,

 Jean

Good to know. Currently right now I have to use the first person controller pre fab with C# scripts, and I'd like to reduce the amount of pre made scripts for practice.
Title: Re: Making a First Person Controller
Post by: coffeeANDsoda on February 17, 2015, 05:30:03 PM
What's the update on this Jean?