Hi all you lovely competent people I'm trying to design a geyser which will shoot players into the sky but I'm running into a couple problems! Most importantly the geyser won't return back to it's starting position by itself (without the player colliding with it after jumping off). Here's my script - Code (CSharp): public class GeyserScript : MonoBehaviour { public Transform pos1, pos2; public float speed; public Transform startPos; Vector3 nextPos; // Start is called before the first frame update void Start() { nextPos = startPos.position; } // Update is called once per frame void OnTriggerStay2D(Collider2D collision) { if (transform.position == pos1.position) { nextPos = pos2.position; } transform.position = Vector3.MoveTowards(transform.position, nextPos, speed * Time.deltaTime); } void OnCollisionExit2D(Collision2D collision) { if (transform.position == pos2.position) { nextPos = pos1.position; } transform.position = Vector3.MoveTowards(transform.position, nextPos, speed * Time.deltaTime); } private void OnDrawGizmos() { Gizmos.DrawLine(pos1.position, pos2.position); } } I'm also planning on having the player get shot upwards off the top of the geyser which I can't figure out although that problem isn't urgent.
If you don't have a Rigidbody2D on this GameObject then you've implicitly set them as static i.e. non-moving so you should not be moving them. If you've got a Rigidbody2D on it then you've implicitly stated that it'll control the Transform and you should not be modifiying it in any way. Make all movements via the Rigidbody2D instead using Rigidbody2D.MovePosition, velocity changes or forces. Also, it's bad comparing floats without a margin of error i.e. doing an approximate compare. Here you're comparing three floats (transform.position) which isn't good. You should test if the sqr-magnitude of the difference between the two positions is above some small threshold instead.