Changing tool grip to look at some position causes it to be negative of the actual lookat cframe

im trying to make a tool point to the mouse cursor, but if i try applying the cframe from the lookat function then multiplying it by the inverse of the origin its weirdly reversed

ive looked at the post How do I make a tool point at the player's mouse? - #2 by azqjanna

it talks about the use of changing the attachment of a rigid constraint in order to change the orientation of some part, but i dont think thats necessary as changing the grip offset i assume is basically doing the same thing for making the tool look in a direction so i repurposed the code for changing the attachments cframe to change the grip

code (its a local script within the handle of a tool)

local oar = script.Parent.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local arrow = workspace:WaitForChild("arrow")

task.wait(1)

local grip = player.Character["Right Arm"].RightGripAttachment

oar.Activated:Connect(function()

	local cframe = CFrame.lookAt(grip.WorldPosition, mouse.Hit.Position)
	oar.Grip = grip.WorldCFrame:Inverse() * cframe
	arrow.CFrame = cframe

end)

i included an arrow which is just a part to show what the cframe of the lookat looks like and what the tool is supposed to look like

thank you

tool.Activated:Connect(function()
	local from = grip.WorldPosition
	local to = mouse.Hit.Position
	local target = CFrame.lookAt(from, to)
	tool.Grip = grip.WorldCFrame:ToObjectSpace(target)
end)

2nd try

2 Likes

this doesnt seem to fix the problem since youre starting from the position of the attachment which is relative to the character and then using its cframe which is relative to the character, thanks for the reply though

1 Like

You could always make your own tool grip using moter6Ds. Make sure to disable some setting in the tool though.

1 Like

thanks for the second try, definitely works a lot better but it encounters the same issue i have where its sort of reversed

maybe, the only thing ive done with motor6ds is just replacing them with ball constraints for a ragdoll. do you mind elaborating on this? like how i would go about it and how to get it to point in the direction of the mouse using motor6ds

The fact you’re just the opposite on that one value makes me think you’re really close. Maybe someone else will know for sure… I’m kind of speculating here, with nothing to work with.

1 Like

Well you would basically put a moter6D into the player’s character every time it loads and then attach the moter6d part0 to a player torso or anything and then whenever a tool is equipped change the part1 to that tool and when its unequipped change back to nil. Etc etc. here are some links: Point a moter6D to a point - #3 by dthecoolest
How to animate Tool Parts (Guns, Knifes etc.)

1 Like

Could the problem be it is at world CFrame?

1 Like

maybe, i actually tried just reversing the orientation and it isnt really reversed sort of just reflected alongside an axis

1 Like

I found a post about this: the problem appears to be with local vs global positioning.

1 Like

thanks for the links, im not entirely sure if this would change the results but considering people use it maybe its more reliable than grips, but i have a feeling the issue isn’t really at fault with the grips and its something just wrong with the inverse of the grips world cframe for some reason as the cframe from the lookat is entirely fine

im still not sure why for some reason the orientation is reflected over some axis

1 Like

Just wondering, what is the tool object grip at? 0,0,0? Like the handle. You might have to account to that.

1 Like

skimming over it im not entirely sure its the same problem as me, looking at how similar their examples are it looks like an issue with computation and alignment stuff honestly i cant really grasp it when they start mentioning dot products and derivatives

Yeah, I am just throwing out ideas ngl.

1 Like

i havent messed with it at all since ive been trying to get this to work, also i couldnt see it as a visible property to easily adjust so its probably 0,0,0

thats fine thanks for trying

character limit

1 Like

One last idea: change the handle instead of tool.grip?

1 Like

thats basically what ill fall back on if this doesn’t work, only issue is that im pretty sure its 100% falling through the map after i rip it of its grip and mess with it so ill probably just throw something hacky together

Thats where the moter6D comes in

1 Like