Search code examples
objectunity-game-enginemove

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?


Solution

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