playMaker

Author Topic: Issue with using "Controller is Grounded" for third person character.  (Read 9068 times)

HyperThermal

  • Playmaker Newbie
  • *
  • Posts: 13
I've been learning PlayMaker steadily, and I've been enjoying it thus far, save for one issue. I've been trying to set up a FSM that allows for basic character movements, including jumping, falling, walking, etc. I've managed to get a decent falling state, as well as an idle state that have good transitions between the two, but I can not get a transition from walking to falling. Three outcomes happen from what I've tried: the character keeps on walking at the same altitude even when they should be falling, until they get to the idle state, when they fall accordingly; the other outcome is that the character rapidly switches between the falling state and walking state when on the ground; the last is that there's a huge loop that keeps the character in the idle state.

What methods should I do to fix this?

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: Issue with using "Controller is Grounded" for third person character.
« Reply #1 on: December 30, 2014, 12:12:39 PM »
For the idle--->falling problem you can have your falling state transition from "any state"

I found the "controller is grounded" does do the rapid switching as well- so I use controller is grounded to do a primary check- then I use a raycast from the characters foot to do a secondary check- if both return true then I know the controller is grounded-

I had a problem with falling as well- the best tip I've found was from Jean on these boards wherein you use "get velocity" or get speed on your player and watch the y velocity/speed whenever it goes negative like -0.1 you know the character is falling- you can use that to set the falling state-
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

HyperThermal

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Issue with using "Controller is Grounded" for third person character.
« Reply #2 on: December 30, 2014, 12:38:02 PM »
For the idle--->falling problem you can have your falling state transition from "any state"

I found the "controller is grounded" does do the rapid switching as well- so I use controller is grounded to do a primary check- then I use a raycast from the characters foot to do a secondary check- if both return true then I know the controller is grounded-

I had a problem with falling as well- the best tip I've found was from Jean on these boards wherein you use "get velocity" or get speed on your player and watch the y velocity/speed whenever it goes negative like -0.1 you know the character is falling- you can use that to set the falling state-

The raycast tip sounds like some good advice. However, the first part I am having some trouble with. I don't know how to set up a transition from "any state". Does this involve making a state just for that, or is it an action or event?

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: Issue with using "Controller is Grounded" for third person character.
« Reply #3 on: December 30, 2014, 01:52:28 PM »
If you look in the mecanim window there should be a blue "any state" in there- you just make a transition from that to "falling" and set the condition
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

HyperThermal

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Issue with using "Controller is Grounded" for third person character.
« Reply #4 on: December 30, 2014, 02:50:53 PM »
I have not used mecanim quite yet. I'm waiting until I have the character controller movement down solid before using mecanim. Unless, of course, you mean to tell me that using mecanim is best for character movement.

This is my first time doing something like this, so I'm still fairly inexperienced with this sort of thing.

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: Issue with using "Controller is Grounded" for third person character.
« Reply #5 on: December 30, 2014, 03:11:17 PM »
Thats a good strategy- mecanim doesn't deal with the movement in most situations just the animations-so it doesn't deal with joystick/controller input itself but you pipe that in to mecanim and it will play the correct animations etc-
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

HyperThermal

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Issue with using "Controller is Grounded" for third person character.
« Reply #6 on: December 30, 2014, 06:09:16 PM »
I've had issues with using raycasts, or at least figuring them out. I can not get them working.

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: Issue with using "Controller is Grounded" for third person character.
« Reply #7 on: December 31, 2014, 12:34:34 PM »
There's a few good playmaker/raycast tutorials on youtube- they really helped me-

Also by default raycasts will hit everything- try using the layer mask- and only include your floor type objects- stuff the player can run/jump on- that solved some problems I was having at first-
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

HyperThermal

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Issue with using "Controller is Grounded" for third person character.
« Reply #8 on: January 06, 2015, 12:26:45 AM »
Coming back to this, and I believe that this script from the Unity API is a bit of what I am looking for. All I need is to figure out how to adapt it in PlayMaker.

Code: [Select]
/// This script moves the character controller forward
/// and sideways based on the arrow keys.
/// It also jumps when pressing space.
/// Make sure to attach a character controller to the same game object.
/// It is recommended that you make only one call to Move or SimpleMove per frame.

var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;

private var moveDirection : Vector3 = Vector3.zero;

function Update() {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
                        Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;

if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}

// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;

// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}

http://docs.unity3d.com/ScriptReference/CharacterController.Move.html

HyperThermal

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Issue with using "Controller is Grounded" for third person character.
« Reply #9 on: January 07, 2015, 01:17:12 PM »
Is the above script even possible to replicate in PlayMaker? I'm at my wit's end trying to figure this stuff out.

HyperThermal

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Issue with using "Controller is Grounded" for third person character.
« Reply #10 on: January 17, 2015, 12:13:15 AM »
Bump?

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: Issue with using "Controller is Grounded" for third person character.
« Reply #11 on: January 17, 2015, 06:38:09 PM »
Yes it is possible- I built my own 3rd person controller with PM following youtube tutorials listed here on the tutorial page-

Use "Get axis vector" action with "Controller simple move" action to replicate the movement part of that script-

You can use "Smooth look at direction" to have the character look in the direction of movement you get using the Horizontal axis in "Get axis"

You have several ways to do a jump- I grabbed the jump script from the Unity Sample Assets beta third person controller and use "Set property" to activate it- but the most common way is to use force on the y axis-

If you just wanted a basic third person humanoid to move the easiest thing to do is make sure they are defined as a mecanim "humanoid"- get the Sample assets beta and use the third person character prefab- just replace "Ethan" with your character and it will just work-
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

HyperThermal

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Issue with using "Controller is Grounded" for third person character.
« Reply #12 on: January 20, 2015, 09:10:52 PM »
I have some good news: I have managed to make things work out for detecting whether the character is grounded or not. The solution for this bit is to have some negative Y force even when the character is grounded.

Now, I just need to work in jumping. The way I want to do jumping involves increasing the height while the jump button is held down. The issue I have with current solutions is that either the character goes up constantly while the button is held down. I would try an animated float, but that does not seem to solve the issue, but it does put much needed easing when the character reaches the arc of the jump.

I will show the full FSM for reference once I've figured this all out.

HyperThermal

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Issue with using "Controller is Grounded" for third person character.
« Reply #13 on: January 27, 2015, 10:39:32 PM »
This link shows the Grounded state.
http://puu.sh/f5gAl/6a8a2d7a39.png

This link shows the In Air state.
http://puu.sh/f5gC9/f710d611bf.png

I could not get jumping to work satisfyingly, and I don't think that using a character controller would be good at all, since jumping is too hard to do, and you can't really make any non-humanoid characters with it.