- Home /
Lerp in circular motion
Hi, right now I calculate the distance from my player and the nearest object, then my player lerps to the object. This works fine but I would like to make my player move in a circular motion to the nearest object.
The code i have right now to lerp;
if (Input.GetKeyDown(KeyCode.W))
{
canJump = true;
}
if (canJump)
{
transform.position = Vector3.Lerp(transform.position,
closestPlat.GetComponent<Renderer>().bounds.center + new Vector3(0,
platformHeight, 0), Time.deltaTime * jumpspeed);
}
What i tried:
if (Input.GetKeyDown(KeyCode.W))
{
canJump = true;
}
if (canJump)
{
transform.position = transform.position + new Vector3(0, jumpforce, 0) *
Mathf.Sin(Mathf.PI * (Time.deltaTime) * jumpspeed);
transform.position = Vector3.Lerp(transform.position,
closestPlat.GetComponent<Renderer>().bounds.center + new Vector3(0,
platformHeight, 0), Time.deltaTime * jumpspeed);
}
pic.png
(42.9 kB)
Comment
Best Answer
Answer by David_Simoniants · Jul 18, 2018 at 02:57 PM
Use Vector3.Slerp
method. Docs
Suppose your starting point is A, the goal is B, the center of circle is O
You can calculate current position of your object so
C = Vector3.Slerp(A - O, B - O, lerpValue) + O;
Your answer
Follow this Question
Related Questions
Help with acceleration on a grid 0 Answers
Creating Circular motion to Rigidbody using AddForce 0 Answers
Unity 2D Scripted Movement 2 Answers
Rigidbody object intersection 0 Answers