Page 1 of 1

Move Script Problem

Posted: Mon Sep 27, 2010 3:11 pm
by Jediknight846
I have a cube with this script:

Code: Select all

var moveSpeed = 1;
var turnSpeed = 1;

function Update () 
{
    if(Input.GetButton("W"))
    {
        transform.position += transform.forward * moveSpeed * Time.deltaTime;
    }
    if(Input.GetButton("S"))
    {
        transform.position += -transform.forward * moveSpeed * Time.deltaTime;
    }
    if(Input.GetButton("A"))
    {
        transform.eulerAngles.y += -turnSpeed * Time.deltaTime;
    }
    if(Input.GetButton("D"))
    {
        transform.eulerAngles.y += turnSpeed * Time.deltaTime;
    }
}
it moves great, but if he tips forward, and I press "W" he, moves down, how do I fix this?

Re: Move Script Problem

Posted: Mon Sep 27, 2010 4:23 pm
by SpiritWebb
If he tips forward and your want to correct that so hes straight again and doesnt go forward when you do, use a different key other then W. Assign a different one. For my space game, I assigned Q and E. E speeds up and Q slows down.

Re: Move Script Problem

Posted: Mon Sep 27, 2010 5:25 pm
by Jediknight846
SpiritWebb wrote:If he tips forward and your want to correct that so hes straight again and doesnt go forward when you do, use a different key other then W. Assign a different one. For my space game, I assigned Q and E. E speeds up and Q slows down.
That won't fix anything.

Re: Move Script Problem

Posted: Tue Sep 28, 2010 2:14 pm
by hallsofvallhalla
use global position not local position....