- Home /
Question by
WesterlyCarrot9 · Apr 25, 2013 at 12:54 AM ·
javascriptcollidercubeupdown
Up and Down Cubes Shaking Issue.
Ok so i use the code below for my cubes to go up and down in the Y axis. I just want that simple thing. Up and Down so that my player (First Person Controller) can go up and jump to the next. The only problem is that when the player is on the cube, the cube or should i say all the cubes start shaking. Is there a way to fix this? Is there a simpler code?
var maxUpAndDown : float = 1; // amount of meters going up and down
var speed : float = 50; // up and down speed
protected var angle : float = -90; // angle to determin the height by using the sinus
protected var toDegrees : float = Mathf.PI/180; // radians to degrees
protected var startHeight : float; // height of the object when the script starts
function Start(){
startHeight = transform.localPosition.y;
}
function Update(){
angle += speed * Time.deltaTime;
if (angle > 270) angle -= 360;
transform.localPosition.y = startHeight + maxUpAndDown * (1 + Mathf.Sin(angle * toDegrees)) / 2;
}
Comment
Try using LateUpdate() rather than Update() and see what happens.
I had a problem like this in the past and found that using RigidbodyInterpolation.Interpolate helped a lot.
@numberkruncher - good call. I'm betting that he has the camera tied to his player, so it's not the cubes that are moving, but the player and the camera, so it just appears that the cubes are moving.