- Home /
Problems with jumping/ landing
Hi! I´m making my first thirdperson-game and I'm having a problem. My jump animation/ transform worked just fine when I didn't have any landning animation, but when I added a "roll" animation as a landing, the jump animation started to bug. 2/3 of every jump is extremely high. Why does this happen?
Sorry if my grammar is bad but I think everything understandable...
I uploaded my game at itch.io right here. And remember that this is just a pre-alpha on the demo thats never gonna be a real game. I'm just learning.
Thanks.
MoveBehavior Code:
using UnityEngine;
using System.Collections;
public class MoveBehaviour : GenericBehaviour
{
public float walkSpeed = 0.15f;
public float runSpeed = 1.0f;
public float sprintSpeed = 2.0f;
public float speedDampTime = 0.1f;
public float jumpHeight = 1.0f;
private float speed;
private int jumpBool;
private int groundedBool;
private bool run;
private bool jump;
void Start()
{
jumpBool = Animator.StringToHash("Jump");
groundedBool = Animator.StringToHash("Grounded");
anim.SetBool (groundedBool, true);
behaviourManager.SubscribeBehaviour (this);
behaviourManager.RegisterDefaultBehaviour (this.behaviourCode);
}
void Update ()
{
run = Input.GetButton ("Run");
if(Input.GetButtonDown ("Jump"))
jump = true;
}
public override void LocalFixedUpdate()
{
MovementManagement (behaviourManager.GetH, behaviourManager.GetV, run);
JumpManagement();
}
void JumpManagement()
{
if (anim.GetBool(jumpBool) && rbody.velocity.y < 0)
{
jump = false;
anim.SetBool (jumpBool, false);
}
if (jump && !anim.GetBool(jumpBool) && IsGrounded())
{
anim.SetBool(jumpBool, true);
if(speed > 0)
{
rbody.AddForce (Vector3.up * jumpHeight * rbody.mass * 10, ForceMode.Impulse);
}
}
}
void MovementManagement(float horizontal, float vertical, bool running)
{
if (anim.GetBool(groundedBool))
rbody.useGravity = true;
Rotating(horizontal, vertical);
if(behaviourManager.IsMoving())
{
if(behaviourManager.isSprinting())
{
speed = sprintSpeed;
}
else if (running)
{
speed = runSpeed;
}
else
{
speed = walkSpeed;
}
}
else
{
speed = 0f;
}
anim.SetFloat(speedFloat, speed, speedDampTime, Time.deltaTime);
}
Vector3 Rotating(float horizontal, float vertical)
{
Vector3 forward = behaviourManager.playerCamera.TransformDirection(Vector3.forward);
forward.y = 0.0f;
forward = forward.normalized;
Vector3 right = new Vector3(forward.z, 0, -forward.x);
Vector3 targetDirection;
float finalTurnSmoothing;
targetDirection = forward * vertical + right * horizontal;
finalTurnSmoothing = behaviourManager.turnSmoothing;
if((behaviourManager.IsMoving() && targetDirection != Vector3.zero))
{
Quaternion targetRotation = Quaternion.LookRotation (targetDirection);
Quaternion newRotation = Quaternion.Slerp(rbody.rotation, targetRotation, finalTurnSmoothing * Time.deltaTime);
rbody.MoveRotation (newRotation);
behaviourManager.SetLastDirection(targetDirection);
}
if(!(Mathf.Abs(horizontal) > 0.9 || Mathf.Abs(vertical) > 0.9))
{
behaviourManager.Repositioning();
}
return targetDirection;
}
}
Your answer
Follow this Question
Related Questions
Not able to jump when running!Where did I go wrong? 1 Answer
Controller like CubeWorld 0 Answers
Itwen MoveTo - jump 1 Answer
Trouble with spring platform 0 Answers
Unity3D HELP! How can i pickup/hold/throw object when im rolling ball? 4 Answers