Issue constraints and attachments with one of the 4 parts being teleported up?

Issue:
When I am creating my car chassis, I am using Cylindrical constraints and attachments along with springs which haven’t yet been added as I believed them to be causing the issue. Each of the cars wheels have their own attachments pre-set in them. They work fine until adding in the Cylindrical Constraint where the FL (Front Left) wheel is moved upwards. I will attach a repro place file.

Vehicle Chassis Issue Repro file.rbxl (462.6 KB)


Code:

-- // Contrainst:
for i, wheel in pairs(script.Parent.Parent.Main.Wheels:GetChildren()) do
	local WheelOriginCFrame = wheel.PhysicalWheel.CFrame
	-- // Set Attachments in this loop@:
	local Attachment0 = Instance.new("Attachment")
	local Attachment1 = wheel.PhysicalWheel.Attachment1
	
	Attachment0.Parent = platform
	
	-- // Set position of attachment0 above that of attachment 1:
	Attachment0.WorldPosition = Vector3.new(Attachment1.WorldPosition.X, Attachment0.WorldPosition.Y, Attachment1.WorldPosition.Z)
	
	-- // Set CylindricalConstraint:
	local Cylindrical = Instance.new("CylindricalConstraint")
	Cylindrical.Attachment0 = Attachment0
	Cylindrical.Attachment1 = Attachment1
	Cylindrical.Parent = platform
	
	wheel.PhysicalWheel.CFrame = WheelOriginCFrame
end

Any help would be greatly appreciated.

1 Like

I changed the code around a little bit and its sort of made the problem worse?

Heres a image and updated code using springs and properties:

for i, wheel in pairs(script.Parent.Parent.Main.Wheels:GetChildren()) do
	local WheelOriginCFrame = wheel.PhysicalWheel.CFrame
	-- // Set Attachments in this loop@:
	local Attachment0 = Instance.new("Attachment")
	local Attachment1 = wheel.PhysicalWheel.Attachment1
	
	Attachment0.WorldOrientation = Vector3.new(0,0,-90)
	
	local prefix = string.sub(wheel.Name, -2, #wheel.Name)
	
	local Cylindrical = Instance.new("CylindricalConstraint")
	Cylindrical.Attachment0 = Attachment0
	Cylindrical.Attachment1 = Attachment1
	Cylindrical.Size = 0.15
	Cylindrical.Visible = true
	Cylindrical.RotationAxisVisible = true
	Cylindrical.Enabled = true
	--Cylindrical.Active = true
	Cylindrical.AngularVelocity = 0
	Cylindrical.MotorMaxTorque = 0
	--// Limits
	Cylindrical.LowerLimit = 0
	Cylindrical.Restitution = 0
	Cylindrical.UpperLimit = 0
	Cylindrical.ActuatorType = Enum.ActuatorType.None
	Cylindrical.LimitsEnabled = true	
	
	if prefix == "FL" or prefix == "RL" then
		Attachment1.WorldOrientation = Vector3.new(90,-180,0)
		Cylindrical.InclinationAngle = -90
	else
		Attachment1.WorldOrientation = Vector3.new(-90, 0, 0) -- -90
		Cylindrical.InclinationAngle = 90
	end
	
	Attachment0.Parent = platform
	
	-- // Set position of attachment0 above that of attachment 1:
	Attachment0.WorldPosition = Vector3.new(Attachment1.WorldPosition.X, Attachment0.WorldPosition.Y, Attachment1.WorldPosition.Z)
	
	-- // Set CylindricalConstraint:
	Cylindrical.Parent = platform

	
	-- // Spring:
	local Spring = Instance.new("SpringConstraint")
	Spring.Attachment0 = Attachment0
	Spring.Attachment1 = Attachment1
	Spring.Visible = true
	Spring.Color = BrickColor.Red()
	
	-- // Spring Properties:
	Spring.Enabled = true
	Spring.Damping = 250
	Spring.FreeLength = 2
	Spring.Stiffness = 10000
	Spring.Coils = 8
	Spring.Radius = 0.4
	Spring.Thickness = 0.1
	Spring.Parent = platform
	
	wheel.PhysicalWheel.CFrame = WheelOriginCFrame
end
1 Like