I am attempting to get an angle in which the character would be launched in the direction that the blue line is shown, while a projectile would be in the direction of the red line. I’m not the greatest with CFrame so I need a bit of help on how this would be done
The angle between the 2 vectors can be found from their dot product. The cross product of the 2 vectors will give you a unit vector pointing in the direction of their cross product. You can use the cross product of the 2 vectors to find the angle between them.
local a = CFrame.Angles(0, rad(45), 0)
local b = CFrame.Angles(0, rad(180), 0)
local c = a:Inverse() * b
local d = c.LookVector
local angle = 0
if d.Magnitude > 0 then
angle = rad(math.deg(math.atan2(d.x, d.z)))
end
print(angle)
Tracking bullet position/orientation would be the best thing to do in your scenario.
When tracking bullet position, use CFrame.new(, ). This creates a CFrame facing the direction your character should be pushed. Use CFrame.LookVector as velocity, multiplied by the strength of the knockback.
If you want to use orientation tracking, directly use <bullet, as a part>.CFrame.LookVector * for knockback.
I’d also advise you to use LinearVelocity instead, BodyVelocity is deprecated. There are various tutorials you can find for LinearVelocity.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.