- Home /
I need help on how to make a Aim Assist aka Auto AIm
I want to make it so when the player aims at a enemy (within x number of feet of the enemy) the aimmer will snap to the target, but will shift off of it if the player moves away from it. I want this because it will make the game a bit easier for the player, thus less likely to frustrate them when there is 20+ enemy's and he cant aim very accurately. I have no idea how to do this and was wondering if someone here could point me in the right direction.
Not sure if it is relevant but I am using ray casting to shoot.
wouldn't you want to do the aim assist in screen space ins$$anonymous$$d of world space?
Answer by spinaljack · Apr 13, 2010 at 03:09 PM
You can use a left 4 dead style subtle aim assist where the aim becomes slower if it's in range of a target so that players spinning around to a target wont shoot past it.
To do this you need to constantly check if the ray cast is hitting a valid target and if so you need to reduce the aim movement by 25% or so, that way it doesn't feel like auto-aim / cheating and the player can still aim at something else with full control.
Something along the lines of:
var aimAssist = 0; var range = 50.0; var aimSpeed = 0.75;
function Update(){ var ray = Camera.main.ScreenPointToRay (Input.mousePosition); var hit : RaycastHit; if (collider.Raycast (ray, hit, range)) { //Debug.DrawLine (ray.origin, hit.point); if (hit.collider.tag == "target") { aimAssist = 1; } else { aimAssist = 0; } } // do your movement controls }
For auto aim that drags the aim towards the target you can use one of the other answers.
If you wouldn't $$anonymous$$d, could you elaborate more on how to adjust the speed actual speed of the aimmer?
That depends on how you've implemented your movement system. If it's done with keys you just multiply the movement by the aim speed adjustment:
var translation = Input.GetAxis ("Vertical") * moveSpeed;
var rotation = Input.GetAxis ("Horizontal") * aimSpeed;
and then adjust the aimSpeed as necessary.
If you need more help please post what code you're using in an edit.
Hello- could you provide evidence/ a source that mentioned L4D has aim assist? As i have used this method of aim assist in a project i am working on and would like to mention the method L4D does this. Would you be able to provide a link to a source that mentioned this please.
$$anonymous$$ind regards and thanks for the help with the code. :)
Answer by Dwair · Apr 12, 2010 at 10:20 AM
Do you have some kind of manual targetting? if not, try to locate the nearest target in sight (using renderer.isVisible() in a loop would do the trick, I think) and just point your raycast to the target coordinates using a Transform.LookAt() object from the startpoint of the raycast and using the LookAt() rotation.
I'm sure there are more simple approaches to that, tell me if you think of a simpler solution, I'm curious about this ;P
This solution doesn't meet the requirement of 'within x number of feet of the enemy'
Raycast can use a fixed max distance, if you use your max lock-on distance you'll have your auto-aim
Answer by Molix · Apr 12, 2010 at 08:29 PM
In a sense, it sounds like instead of shooting out a thin ray, you really want to shoot out a 'tube'. In that case, one approach would be to send out a few more rays around the mouse pointer (maybe 4-8), effectively making the rays into a tube. Then if one of those rays hits something, take the closest one (they could hit different objects), and if it is a new object then snap the mouse pointer to it (don't re-snap immediately to the same object or else you won't be able to move your mouse off of it).
You could try using a capsule collider. I don't know which would be quicker but you would be using an actual tube to detect enemies in range without multiple ray casts which might behave oddly if you don't have enough or spaced too far apart. Although, using a tube would make auto aim behaviour react at a greater angle to close targets unless you use a cone.
Your answer
![](https://koobas.hobune.stream/wayback/20220612155851im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Aiming in code only. 1 Answer
Aim at touch (2D). 2 Answers
I have some issues with my enemy aiming script 0 Answers
Third Person Aiming 0 Answers
FPS Deadzone aim 0 Answers