I am trying to set up a bodyPosition so my player moves to the direct left or right of the camera’s orientation when a button is pressed. I think I may need some trigonometry, but I’m not fully sure. I’m not the best when it comes to math, so i’m wondering if someone can push me in the right direction.
What I Currently Have:
-
the camera’s Y rotation (in radians, if i should change it to degrees lemme know)
-
the distance the player would travel
What I Need:
- the end position
Code:
local function yOrientation(obj)
if obj then
local cframe = obj:ToWorldSpace()
local x,y,z = cframe.Angles
return y
else
return nil
end
end
function physics:LinearThrust(forceType,D,P,maxForce,distance,camCFrame)
print("thrusting!")
if forceType == "BodyPosition" then
local initPosition = self.hrp.Position -- returns vector3
local rotation = yOrientation(camCFrame) or yOrientation(self.hrp) -- returns radian relative to world space
local thrust = Instance.new("BodyPosition")
thrust.Parent = self.hrp
thrust.D = D
thrust.MaxForce = Vector3.new(maxForce,maxForce,maxForce)
thrust.P = P
-- find end position with initial position, distance, and rotation
end
end