How can I keep this from happening?

I have a wheel, that I want it to rotate in both the X axis, and the Y axis at the same time using a weld.

Here is what I mean:

I have tried making the wheel spin in both directions, but when I do… this happens:

Is there anything that I can do to fix this?

Here is the code that I am using:

local suspensionHeight = 5
local weld = script.Parent.Thruster.WheelWeld

game:GetService("RunService").Heartbeat:Connect(function(dt)
	--local velocity = math.floor(script.Parent.Thruster.Velocity:Dot(script.Parent.Thruster.CFrame.RightVector) * dt + 0.5)
	weld.C0 = weld.C0 * CFrame.Angles(0, math.rad(1), 0) + Vector3.new(0, suspensionHeight-weld.C0.Y, 0)
	
	weld.C0 = weld.C0 * CFrame.Angles(math.rad(60) * dt, 0, 0) + Vector3.new(0, suspensionHeight-weld.C0.Y, 0)
end)

Here is the model:

Can someone please help me get this fixed?

1 Like

Did you try using a BodyAngularVelocity?

replace

weld.C0 = weld.C0 * CFrame.Angles(0, math.rad(1), 0) + Vector3.new(0, suspensionHeight-weld.C0.Y, 0)

to

weld.C0 = weld.C0 * CFrame.Angles(math.rad(1), 0, 0) + Vector3.new(0, suspensionHeight-weld.C0.Y, 0)

But then it won’t rotate on both axis’s, and it will only rotate on one axis.

That’s because you are applying offsets on already offset rotations.

local roty = 0
local rotx = 0

game:GetService("RunService").Heartbeat:Connect(function(dt)

    roty = roty+math.rad(1)
    rotx = rotx+math.rad(60) * dt
    weld.C0 = CFrame.new(weld.C0.Position) * (CFrame.Angles(rotx,0,0)*CFrame.Angles(0,roty,0))

end)
4 Likes

Similar thing happens when I use your code:

Don’t use welds for this, it’s redundant when constraints and body moves exists.

Welds don’t work well with wheels, due to the nature of a weld.

I’m trying to make a car that does not use constraints. Hence why I have to use a weld / Motor-6D for this.

1 Like

What’s the reason? CylindicalConstraint would do great here.

2 Likes

Weld is still technically a constraint, but an old and useless one. Motor6D is as well, I believe.

1 Like

I think I should have said why I am using welds for this. I am working on a car chassis that consists of bodymovers and code. Nothing else. Which is why I can’t use the constraints roblox provides us with to build a car (excluding welds).

You’re putting yourself in a bit of an unnecessarily overcomplicated situation.

It may be better to replace your welds with Cylindical Constraints. Welds won’t work well for this.

You can try to use Motor6D as well, but it is a bit more advanced.

Yeah… No, Motor6Ds are still used and will be used for character and other often changing joints. Welds are still used and will be used when a joint which might move but not frequently is required. WeldConstraints are only practical when you have to weld 2 parts together and leave them at it.

His project is a car based on ray-casting and movers/constraints without collideable wheels. It’s way more stable if done correctly.

Also, Motor6Ds literally work the same in this case as Welds, so I don’t see any logic behind the “advanced” part.

1 Like

This seems to be an issue in euler to matrix conversion (converting them manually doesn’t help), but it works perfectly when I set the angles to the Orientation property.

I finally managed to fix this by inverting the rotation matrix.

weld.C0 = CFrame.Angles(-rotx,-roty,0):Inverse()+weld.C0.Position

Edit: Forgot the position…

2 Likes

Good job on getting that solution :slight_smile:
I guess I stand corrected on Welds and Motor6Ds, so thanks for that knowledge!

As for @DragRacer31, I wish you good luck in your project!

2 Likes