I have this mechanic where when you click the mouse anywhere on the screen, the character jumps in that direction.
But the transition isn’t smooth. How can i make it smooth?
Here is the code:
var jumpDelay : boolean;
var doubleJump : int = 0;
private var ray : Ray;
private var rayCastHit : RaycastHit;
function Update()
{
if( Input.GetMouseButton(0) && jumpDelay == false)
{
Jump();
}
}
function Jump()
{
if (doubleJump <= 1)
{
rigidbody.velocity.y = 8;
ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, rayCastHit))
{
transform.position.x = rayCastHit.point.x;
transform.position.x = Mathf.Clamp (transform.position.x, -4, 4);}
jumpTimer();
}
}
function jumpTimer()
{
if (Input.GetMouseButton(0))
{
doubleJump ++;
}
if (doubleJump > 1)
{
doubleJump = 0;
jumpDelay = true;
yield WaitForSeconds(1);
jumpDelay = false;
}
}