Aim assist of sorts

I am making an ability where the user has the aim their mouse at a player to use it, but I would like it to not have to be exactly on them. Making it easier to aim.

I want to avoid creating extra hitboxes when a character gets added if possible. I was looking into mouse.Hit and seeing if it’s near a character but that can be an infinite distance away.

I would like this to be very efficient and not too taxing on the client or server.

You can use world to screen point and compare the possible targets and find which one is the closest to the mouse in a loop.

Should be pretty efficient function to perform compared to region3 or spatial queries.

2 Likes

I’ve looked at this already, I don’t understand how to use it in this situation. Could you please explain? Thank you for the info though.

All sorts of ways you could do this, but an example could be:

  1. On each frame, collect the players that are relevant to the player, i.e. ensure that each of the targetable players are:

    • In front of the client’s camera and/or is within some desired FieldOfView; can be determined using screenspace coords as described below and/or checking the angle between the target and the client e.g. math.acos(cameraCf.LookVector:Dot((targetPos - cameraPos).Unit))
    • Is within some desired distance to the client’s camera, i.e. the magnitude between the target and the client is within either (a) the current weapon’s range, or (b) some other desired distance
    • Whose screenspace position is within some desired range to the centre of the camera, computed via WorldToScreenPoint
  2. Sort the targetable players by one of the values computed above, e.g. the closest player ± least screenspace distance/angle; then iterate through each of the targets until you find an appropriate target, i.e. one that:

    • Is able to be hit, can be checked using a Raycast etc
    • Some other checks that you’d like to perform
  3. Once the best target has been chosen you would interpolate the Camera’s CFrame towards the target based on the computed values, e.g. if using screenspace aim assist:

    • you could move the centre of the camera towards the screenspace coordinate
    • and could attenuate that movement by the distance and smoothed by x smoothing factor etc
2 Likes

Thank you so much! This is going to be very helpful, not just for this project but in the future as well.

1 Like

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