- Home /
I'm trying to create a game that you move forward and back and rotate left and right.
Here is the script.
// Use this for initialization void Start () {
}
// Update is called once per frame
void Update () {
if( !hasAuthority ) {
return;
}
MoveInput = new Vector3(0f, 0f, Input.GetAxisRaw("Vertical") * Speed * Time.deltaTime);
}
public float Speed = 1f;
Vector3 MoveInput;
void FixedUpdate()
{
gameObject.GetComponent<Rigidbody>().velocity = MoveInput;
transform.Rotate(Vector3.up * Input.GetAxis("Horizontal") * Time.deltaTime);
}
The problem is when I rotate the player, it still moves up and down the world Z axis, not the players Z axis.
Help would be awesome.
Good day.
I see you still need some learn about moving objects in Unity. There are so many functions and forms to move an object, like the player.
I recommend you to spend 2-3 hours looking at some tutorials to see whats the best for your propuses. Some of them are relative positions, other are absolute positions, others by forces and masses, others without, etc...
just to commence exploring:
https://docs.unity3d.com/ScriptReference/Transform.Translate.html https://docs.unity3d.com/ScriptReference/Transform-position.html https://docs.unity3d.com/ScriptReference/Rigidbody.AddForce.html https://docs.unity3d.com/ScriptReference/Transform-eulerAngles.html https://docs.unity3d.com/ScriptReference/Transform.Rotate.html
and more...
look the manual, tutorials, youtubes, guides...
Good luck!