Math: Get a point a distance away know the direction

Hi UnityAnswers,

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.

alt text

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:

alt text

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:

alt text

Thanks for your help!

Vector3 greenObjPosition;
Vector3 yourPosition;

Vector3 GetPointDistanceFromObject(float distanceFromSurface){
	Vector3 directionOfTravel = yourPosition - greenObjPosition;

	Vector3 finalDirection = directionOfTravel + directionOfTravel.normalized*distanceFromSurface;

	Vector3 targetPosition = greenObjPosition+finalDirection;

	return targetPosition;
}

The important bit to note is that directionOfTravel.normalized is the Vector with the same direction as before, but with length 1.

// 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);