- Home /
How to make an object move without assigning a rigidbody to it
I have a gameobject that goes up and down by itself. The code is very simple
void FixedUpdate ()
{
rb.velocity = new Vector2(rb.velocity.x, dir);
if (transform.position.y > start)
dir = Mathf.Abs(dir) * -1;
else if (transform.position.y < end)
dir = Mathf.Abs(dir);
}
However, I don't like the fact that it has a rigidbody, because I don't want its movement to be affected when another object eventually collides with it. So would it be possible for the object to continue moving up and down by itself without a rigidbody?
EDIT
Thanks to MT369MT for the solution
I simply replaced
rb.velocity = new Vector2(rb.velocity.x, dir);
with
transform.Translate(Vector2.up * speed);
Answer by MT369MT · Nov 29, 2017 at 07:28 PM
Hi, Try using transform.Translate that doesn’t need a rigidbody.
how would you get that to move smoothly though? iv done a similar thing with translate and it seems to snap to positions
this.gameObject.transform.Translate(Vector3.down theMadHatAttacks.attackValueUp Time.deltaTime);
also it keeps moving slightly as it runs though it with IEnumrators thats probably because its slightly out of place with its starting position though