- Home /
Movement in *any* camera direction.
Hi,
I am looking to learn on how to move in any direction that the camera is facing in a 'zero gravity' environment.
For example if I use the W key I move forward in the direction I face. S key would move me backwards.
The keys A and D would act as left and right strafe.
I have tried to edit the standard first person controller, but like a lot of the standard content in Unity, it seems to be set for ground based FPS, and has loads of excess code which is confusing me. I have spent all day searching for a tutorial on how to do this so I can go through he process, but I've had no luck, which is surprising as I thought this would be a common control method.
I am currently reading up on Unity script (and loving it!) but some help would be very much appreciated.
Thanks
Paul
Answer by whydoidoit · Jun 24, 2012 at 09:52 PM
var speed : float = 10;
function Update() {
if(Input.GetKey("w")) {
transform.position = transform.position + (transform.forward * speed * Time.deltaTime);
}
if(Input.GetKey("s")) {
transform.position = transform.position - (transform.forward * speed * Time.deltaTime);
}
if(Input.GetKey("a")) {
transform.position = transform.position - (transform.right * speed * Time.deltaTime);
}
if(Input.GetKey("d")) {
transform.position = transform.position + (transform.right * speed * Time.deltaTime);
}
}
Thanks $$anonymous$$ike this worked perfectly! $$anonymous$$uch appreciated! I'm off to rip it apart and understand it in more detail.
Paul