Currently have this issue in my isometric shooter game where the guns cant line up properly with the mouse, Here i have a beam to represent where the rifle is aiming in comparison to where my mouse is.
The script i have simply just changes the characters cframe to the mouse position.
That’s due to the depth of the terrain; if you look closely enough the beam does pass parallel to the tile the mouse pointer is currently pointing.
I know, i definately didnt state my issue properly lol. The rifle aims exactly at mouse.p.X, HumanoidRootPart.Position.Y, mouse.p.Z but that poses an issue to aiming as its not in line to where the cursor is. Im trying to see if theres any way to have the characters aim intersect with the cursor instead.
I think you want to trace a line from the camera to the cursor’s position, and find the point on that line that’s as high as your gun’s muzzle where the shots will originate from (maybe if the gun and characters have animations, it’ll be more accurate to use HumanoidRootPart.Position.Y + some offset).
Assuming camPos
and cursorPos
are the positions of the camera and cursor, and muzzlePos
is the position of your gun (or again, HRP with an offset), I think you could find the intersection point with this code:
lambda = (muzzlePos.Y - camPos.Y) / (cursorPos.Y - camPos.Y)
pointPos = camPos + (cursorPos - camPos) * lambda
Try to orient your character towards pointPos. See if it works?
Absolute lifesaver, thank you!!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.