# How could I raycaast with bodymovers?

I am trying to see what this object will touch first, if there any way i can do this?

``````local bv = Instance.new("BodyVelocity") -- Controls The Shot's Height Not Direction (I tested it)
bv.Parent = game.Workspace.Puck
local lesspower22 = lesspower2/2
if power >= 61 and power <= 90 then
bv.Velocity = Vector3.new(0,power / 12,0)
elseif power >= 91 then
bv.Velocity = Vector3.new(0,power / 6.5,0)
elseif power <= 60 then
bv.Velocity = Vector3.new(0,0,0)
end
bv.P = 100000000
bv.MaxForce = Vector3.new(0,1001010,0)
local power2 = power / 3.9
print(power2)
print(CFrame.new(game.Workspace.Puck.Position, mhp).LookVector * power2)
local lv = CFrame.new(game.Workspace.Puck.Position, mhp).LookVector * power2
game.Workspace.Puck.Velocity = Vector3.new(0,0,0)
game.Workspace.Puck.LastShot.Value = game.Workspace.Puck.Position
local imp = game.Workspace.Puck:ApplyImpulse(lv)

``````

If not, could I make another object, speed it up faster than this one and see where that one goes?

You could probably raycast from the body velocity’s parent’s position in the direction of bv.MaxForce.Unit * 5000. The max ray length is 5000 so if anything is beyond that it likely wouldn’t work. Unsure as to whether or not BodyVelocity is relative to the parent part’s CFrame but if it is, you’d have to use cframe:VectorToObjectSpace(bv.MaxForce) then translate it back to world coordinates using cframe:VectorToWorldSpace for direction

1 Like

How would I do this exactly? I’m new to raycasting

Which part are you confused about? If you don’t have any raycasting knowledge you should probably check out a tutorial/introductory post. Here’s one:

I am unsure on how to implement this into a script, would it be something like this?

``````game.Workspace:Raycast(game.Workspace.Puck.CFrame, bv.MaxForce.Unit * 5000)
``````

That looks like it should work, yeah

It works, but how would I be able to do it with the applyimpulse as well? as this one only goes up, I am currently using bodyvelocity to lift the object and applyimpulse to move it forward

I see, I missed that part. Try raycasting in the direction of the part’s AssemblyLinearVelocity instead

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.