Move Script Problem

I wrote a script to make an object move in the direction that I want, but it only controls the speed. Can someone help me on this?

var moveSpeed = 2.0;
var moveSpeed2 = 1.5;

function Update () {
	var x = Time.deltaTime * moveSpeed;
	var y = moveSpeed2;
	transform.Translate(y, 0, x);
}

Can you explain in more detail what you’re trying to do?

make an object move automatically in the direction I specify.

When a key is pressed down??

Probably still need more information. (There are lots of ways to do what you’re asking. I suppose one could just start listing them off, but it’d be easier if we knew exactly what you’re trying to do, and how you want to specify the direction.)

I don’t know how to be any clearer.

Well, try :slight_smile: What kind of object is it? What do you mean by ‘specify its direction’? Do you just want to set its initial transform in the inspector and then have it move along one of its local axes? Do you want to specify the direction as an angle? Do you want it to move towards a target? How is the object represented? Does it use the rigid body or character controller component? Or will you be modifying the transform manually? And so on.

I’m sure you can provide some more information if you think about it a little, and again, any additional information you can provide will make it easier for us to offer specific suggestions.

But, if you just want a suggestion to get started with, here’s one:

transform.Translate(Vector3.forward * speed * Time.deltaTime);

I want it to move automatically on the axis I specify and at the speed I specify. If this helps, It’s a target. I wand it to move across the screen. I’ve done it before but for some reason I can’t get it to work right this time. It just goes in some random direction.

Are you wanting it to move along a world axis? E.g. along the world x axis?

yeah I think. You see, the script I posted in the first post is a variation what I used originally and it worked fine. Now I’m trying to make another set of targets move in the opposite direction but I get a mess of random spinning and weird movement and speed.

Do the new objects have rigidbodies etc attached compared to the originals that are not affected by physics?

No. The are exactly the same. Just different tags.