Original Post
I'm trying to make a gravity well so some object with a velocity will spiral in towards the center of the well as it orbits it. What I have appears to start to work, but then the object circling the well suddenly will fly off away from the well. Here is the code I am using
Another issue I'm having is that when calculating deltaY and deltaX, I'm pretty sure I should be using subtraction. But if I do that, the object doesn't move towards the gravity well at all.
Vector3 gravDir = curGravWellPos - transform.position;
gravDir = gravDir.normalized;
float dT = Time.time - startTime; //current time minus the start time
float dTSqrd = dT * dT;
float deltaY = (velocity.y * dT) + (.5f * grav * gravDir.y * dTSqrd);
float deltaX = (velocity.x * dT) + (.5f * grav * gravDir.x * dTSqrd);
transform.position = startPos + new Vector3(deltaX, deltaY, 0);
Another issue I'm having is that when calculating deltaY and deltaX, I'm pretty sure I should be using subtraction. But if I do that, the object doesn't move towards the gravity well at all.