I have enemies and when they die they spawn an energy ball with a given velocity. I want to move this ball to the player using "gravity" to create a curved path. I have a version of the function but it is not arriving correctly to the end point without tweaking gravity force (if gravity is low, the velocity vector is not changed fast enough to get to the target position). Has anyone done this previously? I prefer to use gravity than a function curve like a bezier.
We can assume player will be stand still. So, it does not move. Target position will remain the same.
Here the code I'm using right now, I'm using unity3d:
float gravityMultiplier = 100;
_gravity = (targetPosition - _t.position).normalized*gravityMultiplier;
_gravity.z = 0;
velocity += _gravity * Time.deltaTime;
_t.position += velocity*Time.deltaTime;
What I'm doing here is just modifying the velocity of the object to make it be attracted by a point at targetPosition. _t is just the gameobject transform.
Thanks in advance.