- Home /
Question by
RedBlackGold · yesterday ·
movetowardsprogramming-basics
MoveTorward teleporting instead of moving usually
The image shows a script which goes on the player, and when entering certain colliders moves towards the object with the collider. For some reason if the object is not at 0, 0, 0 it bugs out, teleporting the player way past the collider or just making them move really fast in a random direction. I do want to keep player velocity after leaving the collider because the object with it does get destroyed later so should I just use rb.velocity, and if so how do I use that?
[SerializeField] float currentGravity;
private void OnTriggerStay(Collider other)
{
if (other.GetComponent<GravityPull>() != null)
{
currentGravity = other.GetComponent<GravityPull>().gravityPull;
transform.Translate(Vector3.MoveTowards(other.transform.position, transform.position, currentGravity * Time.deltaTime));
}
}
Comment