I am attempting to create a speeder bike that uses BodyGyro to rotate the bike and move it towards the player’s mouse. It works pretty well when moving the mouse left and right but for some odd reason the bike starts jolting up and down whenever the mouse is on the lower part of the screen which makes it look very jaggidy.
local Hit = Vector3.new(Mouse.Hit.p.X, 0, Mouse.Hit.p.Z)
local cFrame = CFrame.new(VehicleSeat.Position, Hit)
local Bank = ((((Mouse.ViewSizeX/2)-Mouse.X)/(Mouse.ViewSizeX/2))*0.3*2)
VehicleSeat.BodyGyro.CFrame = cFrame * CFrame.Angles(0,0, -0.3 * (SideSpeed/MaxSpeed))*CFrame.Angles(0,0,math.rad(Bank))
I am confused about what is causing this but I am almost certain it is due to taking the Mouse.Hit x and z positions. Is there a way I can stop this? Such as taking the mouse positions from the screen itself? Any help would be appreciated.
The jolting seems to be from the mouse pointing at the ground and then the bike lifting and moving under the cursor, which makes the bike face itself, which makes it move such that the mouse isn’t over the bike, which repeats the cycle.
This could be fixed by using the mouse’s position on the screen to determine the angle the bike should move toward. Or, some tricky camera math could let the player direct the bike toward the cursor as if the cursor were hitting a flat, level and infinite baseplate.
The bike lifts because the BodyGyro is pointing directly at the cursor, which usually isn’t on the same level as the bike. Thus, it lifts high up when the mouse is near the bike, and less so when it’s far away. You can sort of fix this by removing the x and z components from the BodyGyro’s MaxForce (i.e. only enforce yaw), but it’ll make the bike tip over because there’s nothing keeping it upright.