playMaker

Author Topic: Making a First Person Controller  (Read 50386 times)

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Making a First Person Controller
« 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):



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.
« Last Edit: January 15, 2015, 02:04:32 PM by Alex Chouls »

tobbeo

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 186
Re: Making a First Person Controller
« Reply #1 on: April 04, 2011, 06:53:30 PM »
Thanks for the example :) Straight forward and makes sense.

Steamgauge

  • Playmaker Newbie
  • *
  • Posts: 4
    • Steamgauge
Re: Making a First Person Controller
« Reply #2 on: April 06, 2011, 08:09:29 AM »
Very useful information, thank you!
-

dotty

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Making a First Person Controller
« Reply #3 on: April 11, 2011, 12:05:39 PM »
Any idea's how to make the head movement faster? Seems slow.

MaDDoX

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 165
    • FluidPlay Studios
Re: Making a First Person Controller
« Reply #4 on: April 11, 2011, 08:07:47 PM »
Have you tried playing with the "multiplier" fields in the "Get Axis" actions?
--
Breno "MaDDoX" Azevedo
@brenoazevedo

dotty

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Making a First Person Controller
« Reply #5 on: April 12, 2011, 06:56:13 AM »
yeah, but it seems to mess up the rotation.

MaDDoX

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 165
    • FluidPlay Studios
Re: Making a First Person Controller
« Reply #6 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.
--
Breno "MaDDoX" Azevedo
@brenoazevedo

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Making a First Person Controller
« Reply #7 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!)

dotty

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Making a First Person Controller
« Reply #8 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.

Tinker

  • Playmaker Newbie
  • *
  • Posts: 6
Re: Making a First Person Controller
« Reply #9 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

Deadlyapples666

  • Playmaker Newbie
  • *
  • Posts: 10
Re: Making a First Person Controller
« Reply #10 on: April 22, 2012, 10:21:07 AM »
I wana know this too :O

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Making a First Person Controller
« Reply #11 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

You can check out the games I have already ported:

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

 Bye,

 Jean

Tinker

  • Playmaker Newbie
  • *
  • Posts: 6
Re: Making a First Person Controller
« Reply #12 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
« Last Edit: April 23, 2012, 03:24:00 PM by Tinker »

FractalCore

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 100
Re: Making a First Person Controller
« Reply #13 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.

J1RG

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Making a First Person Controller
« Reply #14 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?
« Last Edit: November 17, 2013, 07:16:08 PM by J1RG »