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

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

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
6 years ago

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.

Ad

Answer this question