- Home /
Question by
HBishop · Jan 26, 2020 at 04:03 PM ·
slerpjumping object
Slerp movement too fast
I'm trying to get the player to move in an arc from point A (Current position) to Point B (Pre determined Position). However, the jump seems to happen instantly and not over a couple of seconds. I've tried using coroutines but this doesn't work either. I think I've gotten confused with the new and old points, but the only way so far that moves the player exactly 2.5f forewards is below. Any help is appreciated
void Start () {
player = GameObject.FindGameObjectWithTag("Player");
xPos = player.transform.position.x;
yPos = player.transform.position.y;
zPos = player.transform.position.z;
startTime = Time.time;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.Return))
{
zPos = zPos + 2.5f;
currPos = new Vector3(xPos, yPos, zPos);
newPos = new Vector3(xPos, yPos, zPos);
centre = (currPos + newPos) * 0.5f;
centre -= new Vector3(0, 1, 0);
riseRelCentre = currPos - centre;
setRelCentre = newPos - centre;
float fracComplete = (Time.time - startTime) / journeyTime;
transform.position = Vector3.Slerp(riseRelCentre, setRelCentre, fracComplete);
transform.position += centre;
}
Comment
Journey time set to 5, but i tried 10 and 1 also
Your answer
Follow this Question
Related Questions
How do I rotate on World Axes with Quaternion.Slerp? 2 Answers
Slerp/Rotational Problem Query 1 Answer
Convert function into a While loop 1 Answer
Vector3.Slerp bumping problem 1 Answer