Top down game 1d aim offset?

I’m trying to update my aiming system for my top-down game, basically you hold right click to turn on aiming, and the player character turns toward the cursor. It should work like this: when the player isn’t aiming at anything special, the aim points straight forward, but when it’s aimed at an enemy for example, the character skeleton should bend vertically, pointing toward the height of the cursor hit, and I assume this is better achieved with a 1d aim offset.

I got it so far, except for the aim offset part:

I don’t really need horizontal offset cuz the character will always be rotated toward the mouse cursor when aiming, and I should add turn in place animations later. but I do need vertical offset

I believe the catch here is what would be the proper way to calculate the offset amount? as you can see, it can’t be just based on the height of the cursor hit, since when pointing at a foot for example, it should look down more and more the closer to the enemy the player is.

Is this even a decent method? how could I achieve this?

ok let me try another way. check this:

so I believe all i need to do is to find the green angle:

how could I do this?

I think I’ve figured it out.

I’m getting a vector from the character’s shoulder height to the cursor hit result, and comparing it to another vector from my character’s pivot to the cursor hit, but at the same height as the character’s pivot, using a dot product and an inverse cosine. (thanks, chatgpt)

it always returns a positive value, so I had to check if the cursor hit result height is greater than the character’s shoulder height, otherwise invert the return value.

:slight_smile:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.