- Home /
Flying Orb Strafe Help C Sharp
In this little game I am working on, I have a little flying orb. I am using the mouse look script from the first person controller, but the movement script is just something I am trying to make to teach myself. Right now it works well. I can move forward with the W key and turn with mouse look and I can fly around using that, but I want to be able to strafe and go backwards as well. Here is the script. using UnityEngine; using System.Collections;
public class Move : MonoBehaviour {
public float forwardSpeed;
public float sidewaysSpeed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKey(KeyCode.W)) {
transform.Translate(Vector3.forward * forwardSpeed * Time.deltaTime);
transform.Translate(Vector3.up * Time.deltaTime, Space.World);
transform.Translate(Vector3.down * Time.deltaTime, Space.World);
if(Input.GetKey(KeyCode.Space)) {
forwardSpeed = 50f;
}
else {
forwardSpeed = 20;
}
}
}
}
Could someone figure out how to make him strafe and move backwards? Also is the way I have the speed boost set up the most efficient. It seems like checking every frame to if the space bar isn't down to set speed to 20 like a bit much. Any help would be much appreciated.
Answer by Berenger · Jun 18, 2012 at 11:01 PM
Why are you translating upward and downward, from the same amount and at the same moment ? They cancel each other.
Anyway, to move backward you need to do like the forward movement -> input detection, Translate( Vector3.back backSpeed Time.deltaTime );. For the straff, the best is probably an animation.
weinermelon : Thank you very much. That helped solve my problem. I had tried writing that before, but I was putting it under the forward control ins$$anonymous$$d of by itself so it didn't work. Thx.