You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
Hello! I am trying to make a car system for my Movie Module so cars go towards a specific part so they drive straight on roads.
What is the issue? Include screenshots / videos if possible!
My problem is that… It can turn in the right direction, but when I try to clamp the wheels the clamping does not work. I tried converting it to a 0 to 360 type rotation instead of 180 and -180, but this does not work either and I am stumped.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
My code is shown below.
car = script.Parent
wheels = car:WaitForChild("Wheels")
mover = car:WaitForChild("Mover")
base = car:WaitForChild("Base"):WaitForChild("Base")
local steer = mover:WaitForChild("Steer")
local throttle = mover:WaitForChild("Throttle")
local pos = script:WaitForChild("Position")
part2 = Instance.new("Part")
part2.Anchored = true
part2.Parent = workspace
function MoveCarTo(Position:Vector3)
local lookAt = CFrame.lookAt(base.Position, Position)
local newPart = Instance.new("Part")
newPart.CFrame = lookAt
local y = newPart.Orientation.Y
part2.Position = base.Position+Vector3.new(0, 10, 0)
part2.Orientation = newPart.Orientation
newPart:Remove()
if y < 0 then
y = 180+math.abs(y)
end
local value = y
print(value)
wheels:WaitForChild("Front"):WaitForChild("WL"):WaitForChild("Connection"):WaitForChild("HingeAttachment0").WorldOrientation = Vector3.new(0, math.clamp(value, 45, 315), 0)
wheels:WaitForChild("Front"):WaitForChild("WR"):WaitForChild("Connection"):WaitForChild("HingeAttachment0").WorldOrientation = Vector3.new(0, math.clamp(value, 45, 315)+180, 0)
end
while wait() do
workspace.Car.MoveToPosition.Position.Value = workspace.Rig:GetPivot().Position -- This just tells the car to go to a rig dummy character in the workspace.
MoveCarTo(pos.Value)
end
apologies if the way I use CFrames isn’t the best, they aren’t my strong suit and I don’t like using them so I often use parts to convert.
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
wait, i think this is on me actually, I got it to stop spinning but the right wheel is facing in the incorrect direction. I will try this to see what it prints. In the meantime, can you tell me how to flip the direction so the right wheel doesn’t spin?
Lol no worries! We’ll figure this out together… If the values are printing correctly and the issue is with the right wheel facing in the incorrect direction, you might need to adjust the sign of the clamped rotation for the right wheel.
-- Replace this line
-- wheels:WaitForChild("Front"):WaitForChild("WR"):WaitForChild("Connection"):WaitForChild("HingeAttachment0").WorldOrientation = Vector3.new(0, math.clamp(value, 45, 315)+180, 0)
-- With this
local rightWheelClampedRotation = Vector3.new(0, math.clamp(value, -315, -45) + currentRotation.Y + 180, 0)
wheels:WaitForChild("Front"):WaitForChild("WR"):WaitForChild("Connection"):WaitForChild("HingeAttachment0").WorldOrientation = rightWheelClampedRotation
Okay, I am back. I would like to try to state my problem better. My main problem is simply put, the wheels often do not point towards the target. Furthermore, another bug is me not completely understanding how to clamp Orientations properly as sometimes it just snaps to something else which makes no sense to me. before I tackle any other problems, Is there a reliable way to clamp an orientation of a part without it freaking out/facing incorrectly?