Little help on understanding a code related to Car System

First of all, Why do I have to Inverse the CFrame I know that the offset will be like this:

Suppose,

A = car.Chassis.CFrame
 and   -A = car.Chassis.CFrame:inverse()

B = thruster.CFrame

if I do the offset thing,Then It will be like: " - A + B or B - A "

*** But I didn’t understand why I have to do the offset.And If anyone can explain this code, It will help me , thank you.!

-- Wheel turning
	local offset = car.Chassis.CFrame:inverse() * thruster.CFrame
	local speed = car.Chassis.CFrame:vectorToObjectSpace(car.Chassis.Velocity)
	if offset.Z < 0 then
		local direction = 1
		if speed.Z > 0 then
			direction = -1
		end
		wheelWeld.C0 = wheelWeld.C0 * CFrame.Angles(0, (car.Chassis.RotVelocity.Y / 2) * direction, 0)
	end

also I know that the rotvelocity of Y is the orientation multiplying its value with -1 or 1 to go rotate it to left or right I guess…

Need a complete explanation to understand this code.Thanks.!

2 Likes

A weld or a motor6d work in a pretty complicated way, the math for them is: CFrame0 * C0 == CFrame1 * C1. That’s why he inverses cframe, for the turnng instead, it checks the Z offset and the speed of the Chassis and thruster and changes the wheel rotation based on it, he also checks speed Z to see if the car is going backward or forward.

1 Like

What is the CFrame0 and CFrame1.?

1 Like

So Cframe0 is the cframe of the part0 of the weld/motor and cframe1 is part1’s.

1 Like

So the CFrame0 is the part0’s world CFrame not the motor one’s …right?

1 Like

Yes exactly, it’s used to compute the offset along with cframe 1

1 Like

and the Z of offset checks that the vehicle is moving forward or backwards…right…?

but speed can increase more than 0 i guess, if speed is greater than zero, then why they need to change the direction to -1…? Explain this pls…