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
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 ![]()
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 ![]()
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)
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 ![]()
shouldnt need to be kinematic tho