Playmaker Forum
PlayMaker Help & Tips => PlayMaker Tips & Tricks => Topic started 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.
-
Thanks for the example :) Straight forward and makes sense.
-
Very useful information, thank you!
-
Any idea's how to make the head movement faster? Seems slow.
-
Have you tried playing with the "multiplier" fields in the "Get Axis" actions?
-
yeah, but it seems to mess up the rotation.
-
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.
-
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'm seeing the inverted camera bug. Could you provide a screenshot of what you think the solution is please.
-
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
-
I wana know this too :O
-
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
-
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
-
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.
-
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?
-
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
-
Any chance of doing the same for a 2D character controller?? I'm struggling... ::)
-
Hi,
yes, this is coming soon with the Unity 2d platform port to PlayMaker.
bye,
Jean
-
Awesome, thanks! ;D
-
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.
-
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.
-
I can´t see the example in the first post for some reason, anyone else have the same problem?
-
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.
-
Hi,
uhm, yes odd, I have contacted Alex on this, he will be able to track this.
Bye,
Jean
-
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.
-
What's the update on this Jean?