I’m trying to animate an object going across the screen smoothly in js. So far I have not been able to do it without lag. Even after I deleted all of my GUI.
Are there any rules or guidelines I should be using?
I’m trying to animate an object going across the screen smoothly in js. So far I have not been able to do it without lag. Even after I deleted all of my GUI.
Are there any rules or guidelines I should be using?
Hello
try this.
in your update function,
speed = Mathf.SmoothDamp(speed,speedToReach, yVelocity, timeToChangeSpeed);
MoveTowards();
in the MoveTowards function :
function MoveTowards () {
if(myWayPoint)
{
var direction = myWayPoint.transform.position - myself.position;
direction.y = 0;
if (direction.magnitude < 0.5) {
return;
}
myself.rotation = Quaternion.Slerp (myself.rotation, Quaternion.LookRotation(direction), rotationSpeed * Time.deltaTime);
myself.eulerAngles = Vector3(0, myself.eulerAngles.y, 0);
var forward = myself.TransformDirection(Vector3.forward);
direction = forward * speed;
var myCharacterController : CharacterController = GetComponent (CharacterController);
myCharacterController.SimpleMove(direction);
}
}
where :
Your character will turn and move towards the target…
give this a try.
hervé
I should have mentioned I’m working on a 2d side scroller where the moving obstacles travel across the screen at increasing rates of speed.
I’m currently trying this ok results, but not great. They still lag and skip at
iTween.MoveFrom(enemy0,{“x”: 540,“y”: 0,“z”: 0, “time”:crossScreenSpeed, “easetype”:“linear”, “oncomplete”:“ResetE0”, “oncompletetarget”:Main_Camera} );
Unfortunately, I’m unable to get your script to move my character forward. It turns towards the waypoint, then starts to slowly drop in the Y, never moving forwards to the target.