Aim Offset for Top Down game?

Hey there,

I’m working on a Top Down prototype of a game, this is a clip of the locomotion system in place to give you better context:

While working on the locomotion, i started having a hard time trying to implement an aim offset system, as you can see in the clip, the character currently turns the entire actor towards the mouse instantly, which was done in the Character and Player Controller BP’s this way:


I need the upper part of the body and the character’s head to turn torwards the mouse around a maximum of 45 to 90 and -45 to -90 degrees to the sides, before triggering a “turn in place” animation, i made the turn in place animations but can’t find good examples that apply to my case, only third person examples, any clues on what is the best approach for this?

Thanks

1 Like

hi,
you could use a DotProduct forward and right to look is the mousePosition is over 0.5 which would be 45°… if it´s over you do rotate in position otherwise you could just use the aimOffset to rotate the upperBody with it´s weapon…

or have 2 dots… one that looks if it´s forward or backward and one for the front/right to see the angle…

hope this helps :slight_smile:

cheers :vulcan_salute:

1 Like

Hello, thanks for the answer!

Although i’m not sure i fully understand it, i’m not very familiarized with the DotProduct node and the more advanced maths, i’m a bit of a beginner on Unreal :sweat_smile:, could you further elaborate on how i would use it? What do you mean by use the DotProduct “forward and right”?

1 Like

hi,

in this tutorial i use the DotProduct to align the character on the vertical axis for strafing… here is a use case and it´s all written, no video, just screenshots…

and this one i made also alot of screenshots and a video :smiley:

when i come back i can make a tittle example but that will take a few hours ~

in this 2 posts you will find the DotProducts for you aiming or character facing…

i would say that DotProduct is one of the most important calculations in gaming math…
Dot product - Wikipedia here is a definition but simple sayed “The dot product, also called scalar product, is a measure of how closely two vectors align, in terms of the directions they point.”

but if you are interested here is a super video https://www.youtube.com/watch?v=MOYiVLEnhrw she is awesome and has alot of useful videos

and this one is also a hit… i really like her… her videos are top notch

back soon but i just found this gem :smiley:
simple math that is genius

hope this helps you :slight_smile:

cheers :vulcan_salute:

2 Likes

Wow, thanks for taking the time for such an extensive answer!

I will give this a try later today and will post how it goes here.

1 Like

hi,
one second i will post you a quick example of usage :wink:

if you like that i will post you the steps :slight_smile:


needs a bit smoothing but this works with a few simple steps

2 Likes

here is the smooth version :slight_smile:


screenshots follow soon

you can also use your input… this is just my character i mess with atm ^^

this is all in abp… better to make it it´s worn component later…



here where the WorldDeltaSeconds get multiplied by 4, this is the smoothing for the aiming



this is on the character…

the function that calls over interface is just a a float for the turn :slight_smile:

hope this helps :vulcan_salute:

2 Likes

This is awesome, once more i appreciate the elaborate explanation, i am still checking those video references, they seem very relevant. Since i’m a 3d artist with almost 0 programming knowledge, i haven’t wrapped my head around all the math behind it yet, so when i can visualize it in practice it helps a lot, i will have to analyze the system a bit more to really understand how it works in practice, but i am getting there.

Now, i was able to reproduce your steps, i think i did it exactly as you showed, i have a few questions, i wasn’t sure of what to do with the “Rotate in Place” function that you created, but eventually i just plugged it straight at the end of my “Event Blueprint Update Animation” exec chain, and it seems to have worked, i think!

I didn’t realize before that the upper body of the character pointing towards the pointer would actually be controlled by another blendspace in this case, how are the poses setup inside that blendspace?

And for the actual turn in place animations, i assume there is no blendspace involved there? Are the turn animations just played based on a state on the state machine like i was doing before? If so, what’s the smart thing for me to be using as a rule of transition from Idle to TurnInPlaceLeft and to TurnInPlaceRight using this system?

Thanks!

1 Like

hi,
i will make you screenshots in a few minutes :slight_smile:

for the turn in place i made a blendspace with TurnInPlace and Idle … i will show you
hmm i am sorry i öet that out, thought you already have your blendspaces, np i will make screenshots from them all step by step

1 Like

hi,
so here are the BlendSpaces… note you could use AimOffset too but then the animations need to be adaptive and your idle animation must be from the same position made… mine is not so i use blendspaces…

ok first here you can find the old 1D aimoffsets / blendspaces

and here are the BlendSpaces

all BlendSpaces use -1 - 1 but you can also make it -90 - 90 if you like… just multiply the DotProduct by 90… but to cut this calculation out i made em only -1 - 1

i combined the idle with TurnInPlace in a 1D BlendSpace… you can make it separate but this should be ok :slight_smile:


here you could make it in 2D and use the Pitch for crouch / stand… then you have idle and turn in place in one blendspace for both situations :wink:

some footage :smiley:

i have the animations from starter pack and als project

if you need help, feel free to write me :slight_smile:

cheers :vulcan_salute:

2 Likes

Thanks a lot, i had to sort out a separate issue with my root bone today, so i haven’t taken a proper look at it yet, i’ll be able to start working on finishing this system and creating the necessary animations when i wake up tomorrow, i’ll post the results here, might poke you in the future! :grimacing:

1 Like

no problem :slightly_smiling_face:

I ended up setting the “Look at” blendspace as an additive of the Turn In Place blendspace inside my Idle state, since in my case, the look at influnces the whole body, and not just the upper part, here goes a video of how it turned out

i’m super happy with how it turned out, and i might want to get a better grasp of how the whole math driving it works before i further increment the locomotion system.

1 Like

that looks great :slight_smile:
Freya Holmér - YouTube here are some great videos about math and other useful information

good luck with your project :+1:

cheers :vulcan_salute:

1 Like

Hi there,

Sorry to revive an older thread. I’m looking to do something similar with character movement, but I’m having some trouble setting up this solution. I’m working on a top down strafe system, but would like to implement turn in place when idle - having no luck so far!

Following these steps, I can get the aim offset to work and I have set up the turn in place blend space, however, the turn only plays once and stops, so I’m clearly doing something wrong.

Is there anyway to access a project file so I can see where I’m going wrong?

hi,
i will upload you the old project files as soon as i am home :slight_smile:

cheers :vulcan_salute:

Thank you so much for replying, I genuinely appreciate it.

I’ve found all of the guidance you provided above regarding Dot product to be extremely useful - it’s great to have someone like yourself who is opening to sharing their knowledge, I can’t tell you how much it helps out!

1 Like

Hey, i saw this a bit late, but i improved this prototype a bit since then:

i changed how my turn in place works, but i am still using that dot product logic that AustrianMunzter shared to get the aim offset, though i don’t fully understand the math behind it yet.

For the turn in place animation itself, i’m doing it a bit differently, using animation curves values to drive the turn in place, it’s probably better to show you how it currently works than to explain:

I converted the “IsTurning” curve to metadata, so it only gives me a 0/1 output, which is useful to determine if we want to turn or not.


Here you can see the TurnInPlaceAmount curve, inside one of my idle turn in place animations, which in my case goes from X:0 and Y:-90 to X:0.6625 (my animation length) and Y:0

State machine:



I’m using this as transition rule from Idle to Turn In Place left/right:

I can’t remember if this was the video i learned it from, but i think he does it the same way: UE 4/5 Turn In Place | Using Animation Curve - YouTube

Hope it helps :slight_smile:

1 Like

Hey, thanks for getting back to me. Your project is looking really good, and the info you supplied is really helpful! I had looked into curve driven rotations and have seen some examples of it put to good use, but the usual camera-driven rotation set ups are not always easily transferred into a top down system - good to see you’ve managed it.

Do you feel you have more control over the turn in place animation now with it being executed in the animation blueprint? I can get the dot product solution working now, but its also introducing some things I need to sort out with regards to aiming, etc, so I’ll probably need to do some further work on the system.

I’m working on a survival horror game which has a shooting mechanic. I planned to use turn in place while idle or aiming while idle. The dot product gets me there, but I don’t understand it enough to make the system precise:

The turn in place solution I have now is cool, and the solution provided by Austrian Munzter has definitely given me some food for thought, but I’d like more control over the rotation. It’s not a major system and can always be revisited, but sometimes you don’t know what you don’t know, so its always super helpful to see how others approach it - thanks again!

1 Like

I like what i ended up with, it does offer more control in regards of playing the necessary amount of the animation according to how much the character is turning, but i might also revisit the system in the future, as there are still a few quirks, for example when i make a turn and i keep turning, doesn’t feel too smooth, you can see it at the end of the video here: