using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour
{
public float forwardSpeed = 75.0f;
public float turnSpeed = 5.0f;
void Update()
{
transform.Translate(Vector3.right * Input.GetAxis("Horizontal") * turnSpeed * Time.deltaTime);
transform.Translate(Vector3.forward * Input.GetAxis("Vertical") * forwardSpeed * Time.deltaTime);
}
}
I am unsure what is happening with this code. Line11 is supposed to make the Gameobject move left/right using the Left/Right arrow keys but instead it is making the GameObject move forward and back.
in addition Line 12 is supposed to make the GameObject move Forward/Back using the Up/Down arrow keys but instead is making it go left/right.
I am at a loss as to what I am supposed to do with this since I am fairly new to programming.
PS Thank you for taking the time to read this Thread.
Use transform.Forward and transform.Right instead of Vector3.Forward and Vector3.Right.
Also you named the variable turnSpeed, but this will not turn it as you are only translating the player transform, not rotating it. Using translate for left/right is equivalent to strafing. Is this what you want?
Note: this makes movement relative. I’m assuming this is what you want?
I had a friend who i didn’t even know was into this help me, he showed me some code that really helped, still a little weird but very manageable. Also I figured out that I indeed did have my GameObject set up sideways, so that was the reason for the controls being opposite. I have since created a new GameObject using some new code and it works. Thankyou all for your help