How would I make an object move according to the player’s mouse? In this case, a plane.
This is what happened with my code:
The object moved way too fast but how do I stop that from happening?
RunService.RenderStepped:Connect(function()
if seat then
local bp = seat.BodyPosition
local bg = seat.BodyGyro
local bav = seat.AngularVelocity
bp.Position = seat.Position + Vector3.new(0, heightIncrease, 0) + mouse.Hit.p
bg.CFrame = seat.CFrame * CFrame.Angles(0, rotation, 0)
bav.AngularVelocity = seat.Position * math.rad(angularVelocity)
end
end)
I believe the issue here is that because you are using a BodyPosition, as soon as your mouse goes off the Baseplate you accelerate extremely quickly due to the far distance of the world edge. Try using a BodyForce or VectorForce as I feel they will be of more use in this situation.
basically you make it rotate to the direction where your mouse is at when it’s occupied, make a math.clamp thingy where the farther the mouse is, the faster it goes (with a limit) same goes with how close it is that it gets even slower vice versa, for this to work you need the seat to be facing the same direction as the car’s main front direction in order for it to work and that it does not go sideways or backwards
it is a math function that has 3 values in left to right order, X, min and max, the X is a value that’s returned after doing its job, if it is in the range between min and max it will return, now if you make it so if it exceeds the maximum (by checking the returned X) you will just fix it to the maximum speed