Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Cybershead on March 11, 2012, 07:13:53 AM

Title: 3rd Person Character Movement
Post by: Cybershead on March 11, 2012, 07:13:53 AM
Hi,

Dose anyone know how to in playmaker or know if a script that can give you great movement and key structure like
Jump
Run
Walk
Kill ,etc

This is something that is not widely avalible on the web, i started to make my own and used a great Wow camera script, but not knowing the script very well at all i have come unstuck.
I brought Playmaker for this reason but the simple 3rd person is not good at all for what i want.
It would be great if someone could tell me of a source to use or buy etc, i was using the script below to move my character and i used a different script to animate. I hope someone can help.

Cybershead

#pragma strict

var walkSpeed = 8.0;
var runSpeed = 10.0;
var jumpSpeed = 10.0;
var gravity = 20.0;
var rotateSpeed = 3.0;


private var grounded : boolean = false;
private var moveDirection = Vector3.zero;

function FixedUpdate() {

var controller : CharacterController = GetComponent(CharacterController);

transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);


var forward = transform.TransformDirection(Vector3.forward);

var curSpeed = walkSpeed * Input.GetAxis ("Vertical");




if(Input.GetKey(KeyCode.LeftShift) && Input.GetAxis("Vertical")) {

controller.SimpleMove(forward * runSpeed);

}




controller.SimpleMove(forward * curSpeed);


if (grounded) {

if (Input.GetButton ("Jump")) {

moveDirection.y = jumpSpeed;

}

}



moveDirection.y -= gravity * Time.deltaTime;


var flags = controller.Move(moveDirection * Time.deltaTime);

grounded = (flags & CollisionFlags.CollidedBelow) != 0;

}




@script RequireComponent(CharacterController)



Title: Re: 3rd Person Character Movement
Post by: justifun on March 12, 2012, 02:35:54 PM
have you watched the 3rd person controller playmaker video?

http://www.screencast.com/users/HutongGames/folders/PlayMaker/media/e73a91a6-8b33-4e6a-8e4c-c4533f32adb6

more screencasts here:

http://www.screencast.com/users/HutongGames/folders/PlayMaker

If so, what don't you like about it?
Title: Re: 3rd Person Character Movement
Post by: Cybershead on March 12, 2012, 04:25:05 PM
Hi justifun,

I think the best thing i can do is make the controller and put them on my site to show you the difference i cam looking for. Thank you for answering my post, will post as soon as i can this week with links.

Cybershead
Title: Re: 3rd Person Character Movement
Post by: Cybershead on March 15, 2012, 04:26:59 PM
have you watched the 3rd person controller playmaker video?

http://www.screencast.com/users/HutongGames/folders/PlayMaker/media/e73a91a6-8b33-4e6a-8e4c-c4533f32adb6

more screencasts here:

http://www.screencast.com/users/HutongGames/folders/PlayMaker

If so, what don't you like about it?


Hi Justifun,

I uploaded my movement that i like and think you cannot do in Playmaker, i know the animation on the jump borked but you get the idea. If you can do this in Playmaker please tell me as when i used the Tutorial my movement was strange.

http://www.unitygamedev.co.uk/gametest/unity/index.html

Thanks

Cybershead
Title: Re: 3rd Person Character Movement
Post by: justifun on March 15, 2012, 08:39:09 PM
Yeah you can totally do that.

Take a look at this screen shot.

Create a cube
Parent your Camera to the cube

Add an FSM to a cube
Create 2 float variables called "HorizontalAxis" and "VerticalAxis"
Use 2 "Get Axis" actions and label the axis names "Horizontal" and "Vertical" (same names as the player input button names)

Increase their multipliers to 2 to make him move faster

Add a translate action and use the "VerticalAxis" variable as the "Z" value
Add a rotate action and use the "HorizontalAxis" variable as the "Y" value

Make sure "Every frame" is checked for both of them.

Voila!

Your cube moves around exactly like your demostration webplayer you posted.

In order to blend the animations, I'd create a second fsm on you cube.

Make the 2 VerticalAxis/Horizontal Axis variable global variables by putting them in the Global Variable section instead

Then on your few FSM, you would use a float compare to check if those variables are equal to 0 or a positive or negative number.

eg: If Vertical Axis is zero then goto a state where you play the idle animation
If Vertical Axis is Greater than 0, goto a state where you play the walking forward animation
If Horizontal is greater than 0 - goto a state where you play the turn right animation
etc etc etc

Try it out and let us know if its the way you were thinking


(http://i.imgur.com/YD3uV.jpg) (http://imgur.com/YD3uV)
Title: Re: 3rd Person Character Movement
Post by: Cybershead on March 16, 2012, 08:09:02 PM
Heya Justifun,

Thats great thank you, i have new faith in PM. But one problem.. Its late and i have not uploaded to my site. but i find that the character will walk on one height and will walk through the mountains, i tried adding gravity etc but it still did the same. Do you have an answer for this? If you need me to upload i will. But i am sure a God of PM will know :)
Thank you for taking your time to help me, i am indented.

 ;D I added a Motor and now it bounces along the surface, i will work on this some more see if i can figure this out. Will upload if i cannot figure this out.


Cybershead
Title: Re: 3rd Person Character Movement
Post by: justifun on March 18, 2012, 12:14:16 AM
I went ahead and made a video tutorial setting up a cube exactly the way your scripted example was made, but with playmaker.

bump it up to 1080P and full screen it to be able to read things clearly.

enjoy!

Edit: Link Fixed

let me know if you have any questions
Title: Re: 3rd Person Character Movement
Post by: terrymorgan on April 16, 2012, 12:29:27 PM
quote
bump it up to 1080P and full screen it to be able to read things clearly
unquote

I could only get 720, could you post the .unity file please?
Title: Re: 3rd Person Character Movement
Post by: Elizeusz on April 17, 2012, 03:24:37 AM
Very good tutorial thank you ! :)
Title: Re: 3rd Person Character Movement
Post by: terrymorgan on April 17, 2012, 11:16:07 AM
K, I have it working sort of, missing all the animations so it's hard to test jump, etc. but I'm not
getting any running when I press left-shift. BTW, justifun, how you came up with this is mind-boggling,
thank you.

http://terrymorgan.net/3rd_person_justifun.unity
69k
Title: Re: 3rd Person Character Movement
Post by: Elizeusz on April 17, 2012, 03:40:21 PM
Hi i have one question. Everything is workin very good for me. But i have some problem with jumping. My character is jumping but when i press left arrow or right and then left ctrl for jumping and then still presing left arrow but not ctrl my character is sliding on the ground not walking or running.

1) ctrl is for jumping
2) arrows ( left , right ) for walking
3) space for running
4) left and right arrow plus ctrl = jump but after that my character i sliding not walkin when he landed

My english is not good but i hope You will understand :)
Title: Re: 3rd Person Character Movement
Post by: justifun on April 17, 2012, 04:39:00 PM
After your character jumps you need to transition back to a state where he is walking or running again.
Title: Re: 3rd Person Character Movement
Post by: Elizeusz on April 18, 2012, 12:48:06 AM
Can You explain me how to do this between two FSM. Walk and run is on the first FSM and jump on second one. Or how to use global transition? I have problem with global transitions not sure how they work.
Title: Re: 3rd Person Character Movement
Post by: justifun on April 18, 2012, 10:33:33 AM
I've been playing around with another method for setting up a 3rd person controller, ill put together a new video when its good to go, but in the mean time, it might be easier to put the jump stuff in with the other walk/run animation section.

Global Transitions area easy to setup. 

In the events tab, make sure you you check the box labelled "global" next to the event you want to create

Now make a new state in your FSM and right click it and choose "add global transition"

Then pick your newly created global event.

Now at any point in that FSM or any other FSM you can use the action "Send Event" or "Send Event on FSM" and you can specify the name of that new global event you created, and the FSM will instantly jump to that state no matter where it is the FSM. 

So you could create one for jumping in the same FSM as the run/walk.....
the run/walk will be connected and go back and forth between each other like in the example.

Create a new Jumping State with a global transition starting it, and an action that plays your animation of your jump on it.  Upon "finished" it should go back to your run or walk, which ever you choose.

Now, on a NEW FSM separate from all of this we'll create a single action that looks for the jump key to be pressed (get key down).  And when it does, it will fire off a second state that will uses the "SEND EVENT" action and will trigger your "jumping" global event back on your run/walk FSM.  We separate this jumping button watching idea onto a different FSM so that it can be running all the time waiting for your jumping button.  Or else you would have to check within every state in your run/walk actions for the jump button.Its just going to be a input manager or watcher if you will.

Hope this makes all makes sense. please feel free to  ask more questions if you need to.

Title: Re: 3rd Person Character Movement
Post by: jeanfabre on April 18, 2012, 11:32:01 AM
Hi Justifin,

 Could you share an actual package of your set up ( minus the playmaker dll of course), then it will be easier to study your example, after having watch the video.

Else, I will make one, no worries.

thanks,

 Jean
Title: Re: 3rd Person Character Movement
Post by: Elizeusz on April 18, 2012, 01:41:37 PM
Hi thank for your explanation they are very god. This is what i have done i will post screen this on one FSM but is working i will try now follow your another explanation with global transitons :)

I have another question. Now everything is working :) but what i can do if my capsule ( character controler ) is not jumping with my character? What i have to add ? I saw that you use character motor is this what i need? If yes where i can find this ?

Title: Re: 3rd Person Character Movement
Post by: justifun on April 18, 2012, 02:20:06 PM
Character motor is going to be automatically get added when you add a character controller or platform input controller to your capsule.  They are found in the standard unity menu in Component - > character controllers (if my memory serves correct - not at my computer at the moment)
Title: Re: 3rd Person Character Movement
Post by: Elizeusz on April 18, 2012, 02:32:57 PM
Componets - physics - character controler but not character motor . Maybe i need to add some standard ssets.
Anyway after adding this one my capsule will jump with my character ? Because now my animations is working and character is mowing up but capsule is still on the ground :D
Title: Re: 3rd Person Character Movement
Post by: Elizeusz on April 18, 2012, 02:37:56 PM
Maybe this question was ask before but if you know can you tell me what i can do to update all this sctions for example i see that there was update on get axis vector and i do not know what i have to do. I bought playmeker and i have one file playmeker 1.3.2. What i need to do ? Is there way to download this fixed actions ?
Title: Re: 3rd Person Character Movement
Post by: justifun on April 18, 2012, 02:47:39 PM
Each action update is included with each iteration of playmaker when its released.

But i not sure if its included in the one you are using (i'm using the latest beta version)

The post about it being updated is here
http://hutonggames.com/playmakerforum/index.php?topic=1302.0

but alex didn't include the updated action with the post.  Usually you can download the specific action and simply overwrite the one in your "actions" folder in the playmaker folder in your scene hierarchy.

Title: Re: 3rd Person Character Movement
Post by: Elizeusz on April 18, 2012, 03:02:20 PM
Thank you :)
Title: Re: 3rd Person Character Movement
Post by: justifun on April 18, 2012, 03:33:24 PM
Over the next week or so i will put together a full blown tutorial for setting up a third person controller system with a source project file etc and accompanying video.
Title: Re: 3rd Person Character Movement
Post by: Elizeusz on April 19, 2012, 12:52:51 AM
Great ! :)
Title: Re: 3rd Person Character Movement
Post by: terrymorgan on April 22, 2012, 08:54:37 AM
Apparently, the Unity file is not useful, here's the unitypackage-

http://terrymorgan.net/3rd_person_justifun.unitypackage
11.3K
Title: Re: 3rd Person Character Movement
Post by: Deadlyapples666 on April 22, 2012, 10:14:18 AM
this tutorial is very useful however.

I have set my own up following a mixture of the tutorials.

My character can strafe left to right and move forwards and backwards and ive added the camera to the sphere as a child and made the mouse rotate the character and as the character rotates so does the camera..

Problems

1. The Capsule rotates up and down when I look up and down :P. Like a rocking egg or something hehe.
2. I cannot jump.. Atleast not as I would hope the jumping to work.. Or would jumping be more related to the animations when I get them in.

Maybe a little details as to what I am trying to achieve :D

I am looking for a camera setup similar to the Witcher 2 or Like World Of Warcraft... but with the Right mouse button held down.. Its like a 1st Person camera functionality but from a 3rd person perspective.

Maybe look at the game Tera. The MMO from Japan. Thats the sort of thing I am aiming for. I am getting together a prototype for an RPG I've written up :)
Title: Re: 3rd Person Character Movement
Post by: justifun on April 22, 2012, 10:27:30 AM
In order to make the capsule not rotate back and forth as you explained, there's 2 ways to accomplish this.

Depending on if you used a rigid body on the capsule or not....
If you did, then check the box labelled "Free rotation X and Z" in the component tab , this will lock its rotation around its Y value (left and right).

If you arn't using a rigid body, then you need to separate out your axis inputs to do 2 different things.

You only want to use the horizontal input for turning your character left and right, so this should only feed into the Y rotation value of the capsule.  

The up and down vertical axis should only rotate your camera that's parented to your character, not the capsule itself.  This will prevent it from rocking back and forth.

You need to have the get axis event in 2 separate locations for different axises. (one on the camera and on the capsule)



There's 2 different ways you can approach jumping.  One is to simply make the animation of your character jumping into the air and leave the capsule on the ground.  This is only handy if you are not using physics at all, and most likely your game takes place on a flat surface. It will appear as if he's jumping but won't be adhering to any of the physics components of unity such as gravity or collisions.

The second involves adding a platform input controller and a character controller component onto your capsule and using the jump provided by unity.

When animating a jump for this method, you need to remove all Y value animation keys before exporting your animation (this will result if your character looking like he's jumping in place).  The up and down translation will come from the physics jumping.  And hopefully will line up with your jumping in place animation to look visually the way you want it to.  It will take some tweaking in both your animation and the character motor values on your capsule.
Title: Re: 3rd Person Character Movement
Post by: Elizeusz on April 23, 2012, 08:42:46 AM
Can You explain me where is platform input controler ? I see character controler but not the other one ... Thanks for secon jump explanation i will use it for sure but i need to know where is platform input controler.
Title: Re: 3rd Person Character Movement
Post by: justifun on April 23, 2012, 10:52:00 AM
Its part of unity's standard assets (character controllers)

Import "character controllers"

Then you can find it in the component menu.

Title: Re: 3rd Person Character Movement
Post by: Elizeusz on April 23, 2012, 01:59:09 PM
I found it :D but after i put it to my capsule and hit play to see waht will hapen i see this error :

NullReferenceException
PlatformInputController.Update () (at Assets/Standard Assets/Character Controllers/Sources/Scripts/PlatformInputController.js:35)

Anyway i see that this script is workin because when i change gravity and speed i see update but i still do not know how to move this capsulle up :D Now when i hit ctrl whiich before i setup for jumping my capsule is still on the ground. I need to use some force on Y ?
Title: Re: 3rd Person Character Movement
Post by: leo_silvas on August 03, 2012, 01:10:05 AM
Justifun, great video tutorial!

Could you post the project that showed the video please? For days I'm trying to understand the system conditions to compare float would help me a lot!
Title: Re: 3rd Person Character Movement
Post by: Nog on January 25, 2015, 05:05:31 PM
Thank you justifun. Your third person controller is excellent, and the video you created really helped me to understand FSM's and global variables. Powerful stuff. Again, thank you for your help.

Nog
Title: Re: 3rd Person Character Movement
Post by: marcustegtmeier on April 07, 2015, 06:04:43 PM
I've been messing with this for a couple days now as I think it's what I need.  My character loads in the scene as a prefab with the camera attached.  For some reason my character will not move directionally but will only rotate despite setting up everything exactly as Justifun did in the video (which I've watched backwards and forwards trying to troubleshoot the problem).  I did get the character to move once by switching the global variable to Rotation Axis instead of Player Axis Magnitude, however the character will only move directionally after rotating to the right first, very strange.  Perhaps I'm missing a script or something somewhere?  Any ideas or tip would be appreciated.

Additionally, I'm trying to figure out how to get the camera to follow the character by moving along the xz plane but not rotating when the character turns.  I'm guessing it has something to do with getting the rotation axis and making it negate a global rotation variable?
Title: Re: 3rd Person Character Movement
Post by: justifun on April 07, 2015, 06:09:03 PM
This video is over 3 years old now, there's probably a better way to do it. Have you tried the camera tutorials here?

https://www.youtube.com/playlist?list=PLC6A20FADF0C7D4FB

Title: Re: 3rd Person Character Movement
Post by: marcustegtmeier on April 08, 2015, 02:44:51 AM
You're right Justifun, I found this video tutorial on another thread When I tried to parent the camera to the player it rotated along with the character.  To fix this I ended up adding this simple controller to my character and then created an empty game object with the same controller on it minus any rotation.  It works for now anyway, we'll see if that causes problems down the road.  This is only used for my "over world" area, any interiors will have a fixed camera.  Now player and camera are loaded dynamically in each scene and it's very clean.