Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Can someone explain how I could make the Velocity of this bv where the player's mouse is pointing?

Asked by 5 years ago

I kinda forgot how to use mouse.Hit (btw, mousehit is defined as mouse.Hit in the local script)

game:GetService("Debris")
script.Parent.SandFlightEvent.OnServerEvent:Connect(function(player, mousehit)
    local char = player.Character
    local bv = Instance.new("BodyVelocity")
    game.Debris:AddItem(bv, 5)
        bv.Parent = char.HumanoidRootPart
        bv.MaxForce = Vector3.new(1e8,1e8,1e8)
    while true do
        wait()
        bv.Velocity = Vector3.new(player.mousehit.lookVector) * 75
        end
end)

1 answer

Log in to vote
0
Answered by
saenae 318 Moderation Voter
5 years ago
Edited 5 years ago

In order to shoot something in a given direction, the idea is to first 'point' the object in that direction, and then apply the velocity to it.

In order to point the object toward mouseHit, you can use the following:

CFrame.new(char.CFrame.p, mousehit.p);

This comes from the form (as shown in the wiki) CFrame.new(Vector3 pos, Vector3 lookAt), which will set your character's HRP to the position pos, while facing lookAt.

As a note, I'm not entirely sure why you're setting your maxforce parameters to 1e8; this is a large number, but it's much more standard to just use math.huge.

I hope this helps.

0
Sorry if i explained it a bit wrong, but I'm trying to make the character fly, using bodyvelocity, and I want them to fly where the mouse is pointing. It's not like a projectile or anything. Nights_Alpha 0 — 5y
Ad

Answer this question