Move Script Problem

got scripts? Need scripts?
Post Reply
Jediknight846
Posts: 9
Joined: Wed Jul 07, 2010 6:48 am

Move Script Problem

Post 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?
:ugeek: May the force be with you! :geek:
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Move Script Problem

Post 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.
Image

Image
Jediknight846
Posts: 9
Joined: Wed Jul 07, 2010 6:48 am

Re: Move Script Problem

Post 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.
:ugeek: May the force be with you! :geek:
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Move Script Problem

Post by hallsofvallhalla »

use global position not local position....
Post Reply

Return to “Scripting/Coding”