Question by
DrewCarter101 · May 03, 2017 at 12:23 AM ·
rigidbodyplayer movement
Player movement (left, right, jump)
So I'm making a simple game where the player can only move, left, right or jump This is the script I have:
public Vector3 jump;
public float jumpForce = 2.0f;
public float speed=10;
public bool isGrounded;
Rigidbody rb;
void Start(){
rb = GetComponent<Rigidbody>();
jump = new Vector3(0.0f, 2.0f, 0.0f);
}
void OnCollisionStay()
{
isGrounded = true;
}
void FixedUpdate(){
float moveHorizontal = Input.GetAxis ("Horizontal");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, 0.0f);
rb.AddForce (movement * speed);
if(Input.GetKeyDown(KeyCode.Space) && isGrounded){
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
isGrounded = false;
}
}
but the two "AddForce" commands seem to mess with each other. Before the jump script worked fine then when I added the movement script, it started moving to high, to fast ad too loosely. I there a better way to do this? Please help, Thank you in advance.
Comment
Answer by Blank1290 · Jul 10, 2017 at 06:13 PM
You should Import 2D package and use the player script in there
Your answer
Follow this Question
Related Questions
How to fix / remove movement jitter from player? 0 Answers
Making a rigidbody "immune" to reacting with another specific rigidbody? 0 Answers
Character Leaning 0 Answers
Player passing through objects 1 Answer
Hitting / Mining / slashing ? 0 Answers