Side scroll Moving Platforms

hello,

How can I make a rigid body box move up and down continuously on the Y axis and left to right continuously on the x axis?

thanks

Well there are many ways to do this, but I think the simpliest way to do it is with a sin curve :slight_smile:

startPosition : Vector3;
speed :float;

function Start ()
{
startPosition = transform.position;
}
function Update ()
{
transform.position = startPosition+Mathf.Sin(Time.time*speed);
}

If this doesn’t work or you need some help with anything else or how this works, don’t hesitate to PM me on the forums.

I can’t guarantee that I’ll see the message immediately, but I’ll try to get back to you :slight_smile:

While your code will do what the OP asks, its poorly written (not as in its bad code, but its definitely the wrong way to do physics)

  1. All physics updates should be done in FixedUpdate
  2. All physics updates should be done with forces/velocity/moveposition/moverotation functions, not updating the position as you do above.

Sorry I didn’t read that it was a rigidbody box

Ok then make the box kinematic and use this

startPosition : Vector3;
speed : float;

function Start ()
{
startPosition = rigidbody.position;
}
function FixedUpdate ()
{
rigidbody.MovePosition(rigidbody.position + Mathf.Sin(Time.time*speed);
}

much better :wink:

shouldnt need to be kinematic tho