Im recreating that one plumber with a red hat kart. I’m trying to have the bottom part of the kart hitbox to somewhat always look at the ground using raycast while checking if it should be turning (if player is using key A or D). And if i try to multiply it by itself it will bug out the alignment to the ground however the rotation will finally work. i’ve tried multiple solutions and can’t figure it with anything.
self.setEngine = function(value)
if value == true then
self.engine = RunService.Heartbeat:Connect(function()
local hit, Position, Normal = Raycast.new(model.PrimaryPart.Position, model.PrimaryPart.CFrame:VectorToWorldSpace(Vector3.new(0,-10,0)) *1)
if self.kartModel:GetAttribute("kmph") == -0 then self.kartModel:SetAttribute("kmph",0) end
if hit and Normal.Y > 0 then
local alignWithGround = math.atan2(Normal.Z, Normal.Y)
local steerRotation = (self.kartModel.PrimaryPart.CFrame * CFrame.Angles(0,math.rad(self.rotation),0)).Rotation.Y
self.kartModel.PrimaryPart.CFrame = CFrame.new(self.kartModel.PrimaryPart.Position) * CFrame.Angles(alignWithGround,steerRotation, 0)
end
self.kartModel.PrimaryPart.CFrame *= CFrame.new(0,0,-self.kartModel:GetAttribute("kmph")) * CFrame.Angles(0,math.rad(self.rotation),0)
end)
end
end