I’m trying to make plane physics in Roblox and I’m using a vector force to make the plane move, I want the vector force to follow the mouse position so the plane moves in the direction of the players mouse.
How could I do this?
Or is there a better way to make plane physics? Let me know!
oh, forgot to mention that you’d change both CFrames to Vector3s of their positions, but here’s an example of getting the direction between 2 Vector3s
local Part1 = workspace.A
local Part2 = workspace.B
-- line segment vector3 from A to B
-- this would be (0,0,100) if A is at (0,0,23) and B is at (0,0,123)
local fromAToB = Part2.Position - Part1.Position
-- distance from A to B
print(fromAToB.Magnitude)
-- direction from A to B
-- this looks like (0,0,-1) or (0,.707,-.707) or (1,0,0)
print(fromAToB.Unit)
Something like this might work: local part = script.Parent
local function onMouseMove(mousePosition)
local force = mousePosition - part.Position
force = force.Unit * 100
part:ApplyForce(force)
end
script.Parent.Touched:Connect(onMouseMove)
The idea is to take the difference between the part’s position and the mouse position. This will give you a vector that points in the direction of the mouse from the part. Then we normalize it to get a unit vector, and multiply it to get a force of the desired magnitude. Finally we apply the force to the part.