I am essentially trying to make a script that pushes any player that comes into contact with a sphere away from it in the opposite direction they came into contact with it. Even if the player comes at it facing backwards, the sphere should still push them away from it. Is there any way to do this? Any help would be appreciated, as I'm not even sure where I'd start with this.
Firstly, you need to get the distance from the character to the object while somehow having an orientation the same as the part looking at the character. We need this because we need to tell which direction the player will move to relative to the object. This can be done with PointToObjectSpace.
--part would be the object (sphere), root would be the HumanoidRootPart from the character who's touching the part. direction = part.CFrame:PointToObjectSpace(root.Position).Unit
direction
is the distance and direction the part is relative to the character (root). I use the Unit function of Vector3 because I want to multiply this value by how many studs we want to travel.
distance = 5 --studs direction = part.CFrame:PointToObjectSpace(root.Position).Unit character:MoveTo(root.Position + direction * distance)
Here you see a multiplication in the direction unit to move it the distance
. We add the current character's position (root) to keep the character in the same position it was in before, just offset by the direction and distance.
CFrame Math Operations --> PointToObjectSpace if you want to learn more of how that works. Hope this helped!