- Home /
Question by
TaylorReich · Jul 30, 2020 at 07:26 PM ·
c#scripting problemphysicsrigidbodyplatformer
How to make Rigidbody.AddForce less delayed in Unity3D?
I'm trying to make it so that when the player in my game moves left or right, he lightly jumps from his current position to his new position. The way I have it set up now, the jump occurs once he has arrived at his new position. What can I do to make it so that the jump happens sooner so that it appears that he jumps to his new position? Here is the code I have that controls that part of his movement:
if (Input.GetKeyDown(KeyCode.LeftArrow) && transform.position.x > minXPos)
{
targetPos = new Vector3(transform.position.x - xIncrement, transform.position.y, transform.position.z);
rb.AddForce(Vector3.up * jumpForceTwo, ForceMode.Impulse);
transform.position = Vector3.MoveTowards(targetPos, transform.position, speed);
isHorizontalingLeft = true;
}
else if (Input.GetKeyDown(KeyCode.RightArrow) && transform.position.x < maxXPos)
{
targetPos = new Vector3(transform.position.x + xIncrement, transform.position.y, transform.position.z);
rb.AddForce(Vector3.up * jumpForceTwo, ForceMode.Impulse);
transform.position = Vector3.MoveTowards(targetPos, transform.position, speed);
isHorizontalingRight = true;
}
Here is a video showing what is happening (sorry it's blurry): https://youtu.be/rPewtb8QywE
Comment