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

How to set BodyForce.Force to mouse's position?

I want to set a BodyForce.Force Vector3 to my mouse's position.


local player = game.Players.LocalPlayer local mouse = player:GetMouse() local part = workspace.Part

part.BodyForce.Force = -- this is were I need to adjust the Vector3 so the part can move to my --mouse's position using mouse.Hit.p


Any suggestions?

1 answer

Bad question but will answer. It's not quite as easy as "set to mouse position", but more like giving it a direction that could reach the mouse position. To get a direction vector you do ( targetVector - originVector ).Unit Multiply this direction for magnitude. For forces you'd use F=MA. so:

local acc = 10 --desired acceleration
part.BodyForce.Force = (mouse.Hit.p - part.Position).Unit * part:GetMass() * acc

However the extra stuff like gravity or friction will make you consider other BodyMovers lol.

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