x


How to make a Mesh collider Move backwards?

hello nathan here. I'm still only a REAL noob at this scripting stuff and need things explained to me.

i don't know how to make my mesh collider (for my tank) to translate backwards on the Z axis?

heres my code:

var speed = 5.0 ;
var rotationSpeed = 5.0;

function Update () 
{
   transform.Rotate(0, Input.GetAxis("Horizontal") * rotationSpeed,0);

   if(Input.GetAxis("Vertical") )
   {
      transform.Translate(0,0,0.2);
   }
}

i haven't linked my speed variable to my script yet. but my problem is, How do i make my tank go backwards? when i push forwards it goes forwards, and when i push back it goes forwards?

any help is truly appreciated. I'm also taking a look at the racing can tutorial.

more ▼

asked Jul 14 '10 at 10:06 AM

Nathan Bennett gravatar image

Nathan Bennett
154 31 33 35

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Take out the if statement completely. It is not needed as you are only checking if you're wanting to move in the vertical direction, not which direction.

Instead put:

transform.translate(0,0,Input.GetAxis("Vertical")*speed);

Input.GetAxis("Vertical") returns a value from -1 to 1, so multiplied by the speed will allow your mesh to move forwards and backwards.

Hope this helped

more ▼

answered Jul 14 '10 at 10:28 AM

Peange gravatar image

Peange
38 2 2 6

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x117
x25

asked: Jul 14 '10 at 10:06 AM

Seen: 1190 times

Last Updated: Jul 19 '11 at 01:48 AM