Vector of the point of a sphere closest to the player

I’m trying to get the vector described in the title. Basically, draw a line between the player position and the center of a sphere, and find the point where the line intersects with the sphere. This is the code I currently have:

World Vector Of(Multiply(Direction Towards(Position Of(Event Player), sphereVector), Subtract(Distance Between(Position Of(Event Player), sphereVector), sphereRadius)), Event Player, Rotation And Translation)

This works, but only when the player is facing a certain way since the vector rotates relative to where the player is facing. Is there a better way to find this, or a way to fix/improve the code?

Maybe try setting Rotation and Translation just to Rotation, to recieve the direction you try to transform with, Translation shifts the Vector as a Position parallel to the direction to obtain a new position instead of a direction.

3 Likes

Changing the transformation to just Rotation doesn’t seem to work, unfortunately… unless I completely missed your point. I’m not really good with vectors :sweat_smile:.

Edit: Ok, I actually figured it out! Instead of finding the world vector relative to the player, I just added the vector of the player position.

Add(Multiply(Direction Towards(Position Of(Event Player), sphereVector), Subtract(Distance Between(Position Of(Event Player), sphereVector), sphereRadius)), Position Of(Event Player))
1 Like

Yeah after i reread everything that part was missing, you defined to where the line will be drawn by a direction, but not from where as compound to the whole formulation, glad you managed it :).

3 Likes

You can do it much easier: Sphere center + direction from sphere to player * sphere radius

Add(sphereVector, Multiply(Direction Towards(sphereVector, Position Of(Event Player)), sphereRadius))

and for copy pasting:

sphereVector + Direction Towards(sphereVector, Position Of(Event Player)) * sphereRadius

Btw, Position Of(Event Player) references the feet of the player, while Event Player references his belly and Eye Position(Event Player) where the camera is located.

1 Like