Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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.

1 comment

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.