Losing my mind over CFrame, please help immediately


this line of code is supposed to make a turret look at a position returned from a raycast (everything checked if ray is nil or not)


but when i aim at the top left, it goes the opposite direction except for the right side of the boat and i have been doing everything to make it work properly, from forums to problem solving, i am losing it. The only one seems to work cause the boat is welded and such, is manipulating the C0 and C1
image

3 Likes

Uhmmm… (Im uncomfortable…)

But is there a reason you’re setting the CFrame position to 0,0,0? Or is it to Object Space?

Try multiplying the turrets CFrame with itself, then applying the CFrame.new().

Also a video might provide more details, if you can share one please.

2 Likes

Try using CFrame.LookAt()

local c1 = CFrame
Turret.C1 = CFrame.LookAt(c1.Position, PositionToLookAt)
2 Likes

image

Putting the X and Z is the only way it able to turn left and right, back and front without Y axis interfering, but the Y axis is not even real because it won’t rotate the gun in any way

1 Like

Vector3 0,0,0 is because of C1 object space, for C0 I have to use the offset I put when I welded the turret

1 Like

I guess try using :Inverse() on your CFrame w out any prior changes, see if it makes a difference?

Or on the lookAt vector at least.

1 Like

still Using @Synitx 's code


like this?

Yeah, but I guess that doesn’t work.

try inverting the vector to a negative. This also might not work.

-Vector3.new(rayPos.X,0,rayPos.Z)

And remove the :Inverse()

If this doesnt work, I guess you will have to look into look vectors.

1 Like

Why not get the player’s mouse and then use mouse.Hit for the CFrame? Is it a server script?

1 Like

Try

local pos = Vector3.zero + (Vector3.xAxis * rayPos.X) + (Vector3.zAxis * rayPos.Z)
C1 = CFrame.LookAt(Vector3.zero, c1:VectorToWorldSpace(pos))
1 Like

the raycast come from the mouse.Hit.Position, the model doesn’t want to face the mouse direction for some reason

So you’re raycasting the mouse hits position so the turret can turn? You don’t have to do that though…

boat.Body.Turret.C1 = CFrame.lookAt(TurretPosition, mouse.Hit.Position)

I don’t know if it will work but I’m trying my best to help :<

1 Like

I wanted to have range and from my experience with mouse.Hit.Position, it goes downhill once I do the .Unit*Range

Alright, some new info, LookVector makes it look slightly up and it stays in place for some reason and the other new info is that it does turn the right way but only when the mouse is hitting something far away

I am so done with CFrames man

image
:stuck_out_tongue_winking_eye:
my sanity :stuck_out_tongue_winking_eye: is gone :stuck_out_tongue_winking_eye: :stuck_out_tongue_winking_eye: :stuck_out_tongue_winking_eye: :stuck_out_tongue_winking_eye:

I made something, test this out though, might not work, and you also have to replace a ton of stuff:

local Player = game.Players.LocalPlayer

local Camera = workspace.CurrentCamera
local Part = workspace.Part

game["Run Service"].RenderStepped:Connect(function()
	local MousePosition = game["UserInputService"]:GetMouseLocation()
	local MousePositionIn3DSpace = Camera:ScreenPointToRay(MousePosition.X, MousePosition.Y)
	
	Part.CFrame = CFrame.lookAt(Part.CFrame.Position, Vector3.new(MousePositionIn3DSpace.Direction.X, 0, MousePositionIn3DSpace.Direction.Y))
end)


1 Like

this indeed does work with normal parts, so the question is why is the turret mesh acting up

I made the mesh on the Y axis of blender with mirror modifier, it should not have any problems with orientations