I’m prototyping a little game and have ran into an immediate math problem. As my math skills are terrible, I can’t wrap my head around how to do this though the concept is very simple.
Here is what I do have:
The player object will move up (automatically) using add force until it collides with the obstacle, which it then stops all force.
When it is attached to the object, and I click, the player will fly away from the object by calculating the angle between the player and the center of the object:
Alright, now here’s what I want to achieve but need help with. When the player hits the object and stops, I want to know a point along the fly away angle (if you can call it that) but a certain distance away from the object. The orbit value:
// vector pointing from the planet to the player
Vector3 difference = player.position - planet.position;
// the distance between the player and the planet
float distance = difference.magnitude;
// the direction of the launch, normalized
Vector3 directionOnly = difference.normalized;
// the force vector for the launch
Vector3 forceVector = directionOnly * desiredForceInNewtons;
// the point along this vector you are requesting
Vector3 pointAlongDirection = player.position + (directionOnly * desiredDistanceInUnits);