How can I change the gun accuracy with mouse, the way the game is design is to rotate the player with mouse position, but the aim are a little off because there are some offset from player position and gun position. how can i make the ray and line renderer to aim/cast the ray where my mouse is.
I’ve been looking for a solution to this and playing with the raycast all day. i have yet to discover how to compensate for that offset, will let you know if i can make it work.
If anyone has figured this out already please help us.
Thanks!
Hi,
Since the gun is firing a straight shot forward from the gun end, all you need to do is to tweak the character rotation to match exactly where the shot is going.
Something like this in the characterController script, play a little with it… these values are for another character I am working in.
After line 8 in the turning method add:
if (playerToMouse.z > 0)
{
playerToMouse.x -= 0.2f;
}
else
{
playerToMouse.x += 0.2f;
}
add a similar if structure for the X axis
if (playerToMouse.x > 0)
{
playerToMouse.y -= somefloatvalue;
}
else
{
playerToMouse.y += somefloatvalue;
}
thanks, i try but it didnt work. here is my solution, i get the position of gun, then subtract it to the position of my player, then add it in the Quaternion rotation
it will work on top down view, but in my current camera with 30 degree, it will look like missing the mouse when shooting left or right. but working fine in the 90 degree.