Phiru
Phiru

Reputation: 49

Unity3d Keep moving an object smoothly

There are lots of similar question in the web.

But all that I've searched are to move from A position to B position.

I can do this with Lerf, MoveTowards and etc.

Anyways, I have a speed value and want to keep moving a gameObject.

Here's my code.

float m_fSpeed = 0.1f;

void Update()
{
   transform.Translate(Vector3.right * m_fSpeed * Time.deltaTime); 
}

I am testing a cube object and with the code the cube doesn't move smoothly as I expected.

Is there another way to move gameobject?

Upvotes: 0

Views: 2691

Answers (1)

Krzysztof Bociurko
Krzysztof Bociurko

Reputation: 4661

You can also use physics for that. Attach a rigidbody and set rigidbody.velocity=Vector3.right*m_fSpeed.

Upvotes: 1

Related Questions