- Home /
How do i make a circular transition for movement between to points
I have a script here which when you hit the arrow keys it pushes an object between 4 different points, and if you hit two at once it sits the object between the two points. the only issue is that when it moves between the points it moves in a straight line. Would there be a way for me to make the transition be a more circular movement than a straight movement? the script is below:
public GameObject OcculusUpPosition;
public GameObject OcculusDownPosition;
public GameObject OcculusLeftPosition;
public GameObject OcculusRightPosition;
if (Input.GetKey(KeyCode.UpArrow))
{
OcculusPosition = OcculusUpPosition.transform.position;
SmoothedOcculusPosition = Vector3.Lerp(transform.position, OcculusUpPosition.transform.position, moveSpeed * 2);
transform.position = SmoothedOcculusPosition;
InUse = true;
transform.rotation = Quaternion.Euler(-90, 0, 0);
}
if (Input.GetKey(KeyCode.DownArrow))
{
OcculusPosition = OcculusDownPosition.transform.position;
SmoothedOcculusPosition = Vector3.Lerp(transform.position, OcculusDownPosition.transform.position, moveSpeed * 2);
transform.position = SmoothedOcculusPosition;
InUse = true;
transform.rotation = Quaternion.Euler(90, 90, 0);
}
if (Input.GetKey(KeyCode.LeftArrow))
{
OcculusPosition = OcculusLeftPosition.transform.position;
SmoothedOcculusPosition = Vector3.Lerp(transform.position, OcculusLeftPosition.transform.position, moveSpeed * 2);
transform.position = SmoothedOcculusPosition;
InUse = true;
transform.rotation = Quaternion.Euler(180, 90, 0);
}
if (Input.GetKey(KeyCode.RightArrow))
{
OcculusPosition = OcculusRightPosition.transform.position;
SmoothedOcculusPosition = Vector3.Lerp(transform.position, OcculusRightPosition.transform.position, moveSpeed * 2);
transform.position = SmoothedOcculusPosition;
InUse = true;
transform.rotation = Quaternion.Euler(-180, -90, 0);
}
if (!Input.GetKey(KeyCode.RightArrow) & !Input.GetKey(KeyCode.LeftArrow) & !Input.GetKey(KeyCode.UpArrow) & !Input.GetKey(KeyCode.DownArrow))
{
OcculusPosition = OcculusIdlePosition.transform.position;
SmoothedOcculusPosition = Vector3.Lerp(transform.position, OcculusIdlePosition.transform.position, moveSpeed);
transform.position = SmoothedOcculusPosition;
InUse = false;
transform.LookAt(Idle_LookatPoint.transform);
}
Answer by tormentoarmagedoom · May 08, 2019 at 09:09 AM
Hello.
Yes, you have multiple solutions.
Solution for more "beautifull" movement results is using animations. With animation you can not only have multiple points of trajectroy, you can also use "curves movement" istead of lines point to point, wich will give you a more "circular" movement.
But if you prefear some code for this, you can simply add some moevent in another axis, i mean:
If the object goes in straight line from (10,0,32) to (-25,0,75), you can modify the Y component during its movement, making sure it rises during first half of the voyage and goes down duiring the second half.
Incrementing Y component in a linear way will give you straight lines, but changing the value in square way will give you a aparabole, so more circular.
Bye!
Your answer
Follow this Question
Related Questions
How to Script "octopus swimming" movement? 2 Answers
Increase speed over time 0 Answers
Why can't i addforce to a rigidbody? 2 Answers
Why isn't my move on collision script working? 0 Answers
GameObject does not move with RigidBody2D velocity. 1 Answer