- Home /
Slerp and Update issues
I've got a slerp function that i used from the unity manual, and it works fine but I wanted the position it slerped to, to update once it had been reached. to a z position 3 units away. I've tried isGrounded bool and Coroutines but nothing seems to allow me to have the player slerp from a to b, and once it reaches b, it then moves to a new position. I've left out the zPosNew increment, but thats the variable I've been trying to increase by 3. The tags TileMove and TileFix are just environment that I want my player to bounce off automatically when they collide.
I've tried rigidbody but the jump isn't accurate and very quickly it is landing almost an entire unit off the mark. I've tried if(isGrounded) but it only works for the first bounce,and when I incremented, it would bounce once, then go zooming off in the z axis at crazy speed
I think it's to do with update function - but I haven't got a clue.
Any help is appreciated!
void Start(){
player=GameObject.FindGameObjectWithTag("Player);
isGrounded=false;
xPos = player.transform.position.x;
yPos = player.transform.position.y;
zPos = player.transform.position.z;
}
void Update(){
startPos = new Vector3(xPos, yPos, zPos);
endPos = new Vector3(xPos, yPos, zPosNew);
GetCentre(Vector3.up, startPos, endPos);
fracComplete = (Time.time - startTime) / journeyTime * speed;
transform.position = Vector3.Slerp(startRelCentre, endRelCentre, fracComplete * speed);
transform.position += centrePoint;
}
public void GetCentre(Vector3 direction, Vector3 startPos, Vector3 endPos)
{
centrePoint = (startPos + endPos) * 0.5f;
centrePoint -= direction;
startRelCentre = startPos - centrePoint;
endRelCentre = endPos - centrePoint;
}
private void OnCollisionEnter(Collision other)
{
if (other.gameObject.CompareTag("TileFix") || other.gameObject.CompareTag("TileMove"))
{
Debug.Log("Landed");
isGrounded = true;
}
}
private void OnCollisionExit(Collision other)
{
if (other.gameObject.CompareTag("TileFix") || other.gameObject.CompareTag("TileMove"))
{
Debug.Log("Leaving");
isGrounded = false;
}
}