Moving a part based on player mouse

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)

This is the video of what happened:

Can someone please help me?
Thanks.

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.

2 Likes

It doesn’t work. I just disappear from the map as soon as I sit on it.

make it move using the direction of the mouse except where the mouse is at instead

I didn’t understand what you meant.

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

1 Like

Would I use body gyro for that?

actually the only problem is about how fast the car moves so you can try using my last method for speeding

math.clamp()?


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

bp.Position = seat.Position + Vector3.new(0, heightIncrease, 0) + (seat.CFrame.LookVector * movement) + Vector3.new()

It takes a Vector3 value. math.clamp() is used to return the largest number.

1 Like

Math.clamp explanation? - #2 by tlr22 close but its used to limit large numbers