Steering Making Full 360 To Get To Desired Orientation

Making a Car and for some reason when I turn the car using an attachments orientation its goes around a full 360 to get to the steering orientation. I had to add 180 to the steering for the Right Wheel as it would have been in the axle if not and I believe this is whats causing the problem.


(picture of issue)

code: (most missing variables should need to be explained for this to make sense… I hope)

driversSeat.VehicleSeat:GetPropertyChangedSignal("SteerFloat"):Connect(function()
		local steerOrientation = Vector3.new(0,self.Steer*-driversSeat.VehicleSeat.SteerFloat,0)
		local axle = components.FrontWheels.FrontAxle

		game.TweenService:Create(axle.PrimaryPart.LeftAttachment,TweenInfo.new(0.4,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{Orientation = steerOrientation}):Play()
		game.TweenService:Create(axle.PrimaryPart.RightAttachment,TweenInfo.new(0.4,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{Orientation = steerOrientation-Vector3.new(0,180,0)}):Play()
	end)
1 Like

Basically just wondering why and how I can fix the 360 problem.

Orientation does some funky things whenever your reach their (-180, 180) degree limits, I would recommend setting the attachment’s CFrame instead.

local steerOrientation = self.Steer * -driversSeat.VehicleSeat.SteerFloat

local attachL = axle.PrimaryPart.LeftAttachment
local attachR = axle.PrimaryPart.RightAttachment

-- NOTE: You might need to change which axis the steerOrientation is on
local goalL = {CFrame = CFrame.Angles(0, math.rad(steerOrientation), 0) + attachL.CFrame.Position}
local goalR = {CFrame = CFrame.Angles(0, math.rad(steerOrientation - 180), 0) + attachR.CFrame.Position}

local tweenInfo = TweenInfo.new(0.4, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
game.TweenService:Create(attachL, tweenInfo, goalL):Play()
game.TweenService:Create(attachR, tweenInfo, goalR):Play()

image
uhhhhhh

uhhhh

Just double checking did you include the position of the CFrame, otherwise the attachment’s position will be affected

-- Do this
CFrame = CFrame.Angles(0, math.rad(steerOrientation), 0) + attach(L/R).CFrame.Position
-- Not this
CFrame = CFrame.Angles(0, math.rad(steerOrientation), 0)

I did it correctly not sure why its like this.

This is what the code looks like I dumbed it down so it fitted more compactly since I like compact code:

local steerAngle = self.Steer*-driversSeat.VehicleSeat.SteerFloat
local axle = components.FrontWheels.FrontAxle

game.TweenService:Create(axle.PrimaryPart.LeftAttachment,TweenInfo.new(0.4,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{CFrame = CFrame.Angles(0,math.rad(steerAngle),0)+FLWheel.CFrame.Position}):Play()
game.TweenService:Create(axle.PrimaryPart.RightAttachment,TweenInfo.new(0.4,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{CFrame = CFrame.Angles(0,math.rad(steerAngle-180),0)+FRWheel.CFrame.Position}):Play()

try using worldcframe (((((((((((((((((

WorldCFrame seems to have fixed the positioning but now when ever the player steers it stops from being lock in by the hinge constraint until the tween finishes.

you can try stopping the tween when the player steers

??? the tween is for the wheels to change orientation stopping it would make the player not able to sterr.

I feel like I had an AHA! You’re adding the wheel’s position (a world position), do the attachment’s position (attachment’s offset) like I had before:

CFrame = CFrame.Angles(0,math.rad(steerAngle),0)+axle.PrimaryPart.LeftAttachment.CFrame.Position})
-- And change for the RightAttachment as well

Believe The Attachment was supposed to also reference the WorldPosition but yes I have change it to use WorldPosition and its worked fine besides the part of it lagging behind

Haha I get the assumption. Just FYI Attachment.CFrame / Attachment.Position is an offset from it’s parent unlike WorldCFrame / WorldPosition. If it’s lagging behind I would still use the CFrame property instead of WorldCFrame.

Tweening steering seems a bit strange. Please explain why you are doing it this way.

I’d just use Motors and set the DesiredAngle of those to whatever it needs to be. The MotorMaxVelocity takes care of the smooth movement.
Motor steering suspension car.rbxm (15.9 KB)

Never really cars and are still learning the best way to create an effective one. Also I didn’t even know a Motor instance existed!

Try the car model I posted before. In the script it explains a lot about car physics for steering and suspension.

Ill have to mess around with the Motor Instance and see what I can come up with thank you for the model I can see something working out with the Rod Constraints.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.