- Home /
Jump animation won't move forwards
Hi!
So I have applied a jump animation to my 3rd person character controller. The issue is that the character won't move forward during the animation. The jump animation jumps in its place, does not jump forwards.
We've tried using rigidbody.AddForce (Vector3.up 200f) and rigidbody.AddForce (Vector3.forward 200f), but the object won't move. I put both of those functions in the void update() function to see if they'd be applied in every frame.
We already have the player moving forward by called an animation and holding "w". But the jump animation just stay's in its place and won't move forwards.
So its pretty much Move - Stop moving and jump - Move again.
Advice? Help?
Sorry I didn't post the code. Here it is.
using UnityEngine;
using System.Collections;
public class PlayerMotor : MonoBehaviour {
public GameObject lina;
public GameObject teleport;
private float _moveSpeed;
private Animator _animator;
public float turningSpeed = 3;
public float jumpSpeed = 8.0f;
public int countdown = 1;
public float runSpeed = 5;
// Use this for initialization
//crap below
void Start ()
{
_animator = GetComponent <Animator> ();
}
// Update is called once per frame
void Update ()
{
if(countdown >=1)
countdown -= 1;
CharacterController controller = GetComponent<CharacterController> ();
//----------------------------------------------------Forward
if (controller.isGrounded)
{
Debug.Log ("Is Grounded");
if (Input.GetKey (KeyCode.W) && Input.GetKey (KeyCode.Space) && countdown <=0)
{
countdown = 90;
Debug.Log (transform.position);
controller.Move(Camera.main.transform.TransformDirection (transform.forward));
transform.position = new Vector3(teleport.transform.position.x,teleport.transform.position.y,teleport.transform.position.z);
//rigidbody.AddForce (5,5,5);
Debug.Log (transform.position);
_animator.SetBool ("Jump", true);
}
}
if(Input.GetKey (KeyCode.W) && Input.GetKey (KeyCode.A)) //Move Forward while rotating 90 degrees left
{
transform.Rotate (Vector3.up, -90 *Time.deltaTime*turningSpeed);
_moveSpeed = 1.0f;
}
else if(Input.GetKey (KeyCode.W) && Input.GetKey (KeyCode.D)) //Move Forward while rotating 90 degrees right
{
transform.Rotate (Vector3.up, 90 *Time.deltaTime*turningSpeed);
_moveSpeed = 1.0f;
}
else if(Input.GetKey (KeyCode.S) && Input.GetKey (KeyCode.A))
{
transform.Rotate (Vector3.up, 90 *Time.deltaTime*turningSpeed);
_moveSpeed = 0.0f-1.0f;
}
else if(Input.GetKey (KeyCode.S) && Input.GetKey (KeyCode.D))
{
transform.Rotate (Vector3.up, -90 *Time.deltaTime*turningSpeed);
_moveSpeed = 0.0f-1.0f;
}
else if (Input.GetKey (KeyCode.W)) //Move Forward
{
_moveSpeed = runSpeed;
}
//-----------------------------------------------------Left
else if (Input.GetKey (KeyCode.A))
{
transform.Rotate (Vector3.up, -90 *Time.deltaTime*turningSpeed);
_moveSpeed = runSpeed;
}
//-----------------------------------------------------Back
else if (Input.GetKey (KeyCode.S))
{
_moveSpeed = 0.0f-runSpeed;
}
//-----------------------------------------------------Right
else if (Input.GetKey (KeyCode.D))
{
transform.Rotate (Vector3.up, 90 *Time.deltaTime*turningSpeed);
_moveSpeed = runSpeed;
}
else if (Input.GetKey (KeyCode.Space) && controller.isGrounded && countdown <=0) //Find a way to jump FORWARD!
{
countdown = 90;
_animator.SetBool ("Jump", true);
transform.position = new Vector3(transform.position.x,1.5f,transform.position.z); //Teleport Up
}
else
{
_moveSpeed = 0.0f;
}
_animator.SetFloat ("Speed", _moveSpeed);
}
void OnTriggerEnter (Collider other) //Item Pickup
{
if (other.gameObject.tag == "Pickup")
{
other.gameObject.SetActive (false);
//count++;
//SetCountText();
}
}
}
Could you post your exact code ?
The code you posted has a syntax error in it.
rigidbody.AddForce (Vector3.forward*200f)
@$$anonymous$$iraSensei: That is because the OP didn't use the code formatting, and thus it comes up italicized like this ;) @$$anonymous$$cFads1: Please don't ask your questions again and again. Why do you have two anyway?
The problem I raised was the missing "*", not the italic words :)
@$$anonymous$$iraSensei: Try putting a word between two "*"s without quotes. This is the result!
Answer by scorched_by_kami · Dec 17, 2014 at 01:36 PM
uh u can either try to make a custom animation on the animator tab which helps a bit and u dont need to use a script
Your answer
Follow this Question
Related Questions
Jumping through the roof! 1 Answer
How do i incorporate a double jump ingame? 1 Answer
Multiple Cars not working 1 Answer