• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
6
Question by xToxicInferno · Apr 11, 2010 at 09:41 PM · aimaiming

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Horsman · Apr 12, 2010 at 11:00 PM 0
Share

wouldn't you want to do the aim assist in screen space ins$$anonymous$$d of world space?

3 Replies

· Add your reply
  • Sort: 
avatar image
6
Best Answer

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image xToxicInferno · Apr 14, 2010 at 11:37 PM 0
Share

If you wouldn't $$anonymous$$d, could you elaborate more on how to adjust the speed actual speed of the aimmer?

avatar image spinaljack · Apr 15, 2010 at 02:57 PM 0
Share

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.

avatar image Rorymclean12 · Feb 13, 2017 at 04:26 PM 0
Share

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. :)

avatar image
0

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Horsman · Apr 12, 2010 at 10:59 PM 0
Share

This solution doesn't meet the requirement of 'within x number of feet of the enemy'

avatar image Dwair · Apr 15, 2010 at 02:32 PM 0
Share

Raycast can use a fixed max distance, if you use your max lock-on distance you'll have your auto-aim

avatar image
0

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).

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Horsman · Apr 12, 2010 at 11:00 PM 0
Share

I don't think this is a good solution.

avatar image spinaljack · Apr 13, 2010 at 03:17 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges