My player wont move and i dont know why
I am making this game from https://www.youtube.com/watch?v=qwuPiaFU37w this series at 32:03 i done everything right in the code but my player just wont move i upped the maxSpeed to 30 and still wont work.
using UnityEngine; using System.Collections;
public class PlayerMovement : MonoBehaviour { public float moveSpeed; private float maxSpeed = 30f;
public Vector3 input;
// Use this for initialization
void Start () {
}
void Update () {
input = new Vector3(Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
if(rigidbody.velocity.magnitude < maxSpeed)
{
rigidbody.AddForce(input * moveSpeed);
}
}
}
Just as a side note you should use FixedUpdate for physics calculations such as adding force to a rigid body. and as ShadyProductions mentioned where do you assign rigidbody? do you notice any messages in the console regarding rigidbody?
Answer by popernennins · Jan 27, 2016 at 05:48 AM
Try adding this: public float moveSpeed and change the speed in the inspector.
Your answer
Follow this Question
Related Questions
Object rotates when moving sideways 0 Answers
How to move 3 players at the same time in V form,How to move 3 characters in the same time in V form 0 Answers
Reduce Player Movement in Air 0 Answers
Player only moves when the key is pressed, not when it's held. 0 Answers
Moving forward seems to be specific to the original direction of the object being controlled 0 Answers