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!
I want to rotate the turret of my car toward the target while the turret still being align with the car.
- What is the issue? Include screenshots / videos if possible!
The turret align properly on flat terrain.
The turret is not align properly on inclined terrain.
Video of the problem: https://youtu.be/ZWuRbjdZE6o
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
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!
I have tried to look the forum for solution but I didnt found something that ended helping me.
Model of the car: https://create.roblox.com/store/asset/18800842920
The default orientation of RotationPart: 0, 0, 90
The default orientation of Chassis: 0, 90, 0
ShootVisualEvent.OnServerEvent:Connect(function(player, RotateToward)
print("Testing")
local RotationPart = Mod.MainBody_Mod
local Chassis = Car.MainBody
-- Step 1: Calculate the direction to the target
local direction = (RotateToward - RotationPart.Position).unit
local lookAt = CFrame.lookAt(RotationPart.Position, RotateToward)
local _, yaw, _ = lookAt:ToEulerAnglesYXZ()
-- Step 2: Get the car's current orientation
local chassisCFrame = Chassis.CFrame
local chassisPitch, chassisYaw, chassisRoll = chassisCFrame:ToEulerAnglesYXZ()
-- Step 3: Create the final CFrame for the turret
local finalCFrame = CFrame.new(RotationPart.Position) * CFrame.Angles(chassisPitch, yaw, chassisRoll + math.rad(90))
-- Step 4: Apply the final CFrame to the turret
RotationPart.CarLinker.Enabled = false
RotationPart:PivotTo(finalCFrame)
RotationPart.CarLinker.Enabled = true
end)
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.