Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
2
Question by CreativeStorm · Nov 02, 2011 at 09:19 PM · androidmobileiphoneaimaiming

Vertical Auto Aiming - whats the best way to do it?

Hi guys,

I'm working on an easy shoot 'em up game for mobiles. According to the limitations to two thumps controlling i need a vertically aiming help. Like in Doom1&2 for example.

My idea right now is to use a collider that scans by tag for enemies and set the next to the player (if any) as the target. I'm using raycasts to shoot...

I'm wondering if this would be to expensive for an android game and if there is a better way. Like shooting more rays up and down and take the one that hits something - with fallback if no enemy was hit.

what do you thing would be the fastes solution?

Comment
Add comment · Show 2
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 DavidDebnar · Nov 02, 2011 at 09:55 PM 0
Share

You could check if the enemy gets rendered and if yes, then check the distance. The lowest distance would be like magnet. And you should make an custom cursor, that would normally go towards mouse but when an enemy is rendered and its distance from player is the lowest one drag the vertical position of the cursor towards it. Long story short. If you wanna let the player control both mouse axis, you have to disable the vertical one when you wanna drag, when not, it is much easier. You just let the player move the horizontal axis and when an enemy is rendered and the distance is the lowest, drag the vertical stuff...

avatar image CreativeStorm · Nov 02, 2011 at 10:14 PM 0
Share

sadly, there is no mouse - it's a mobile game on Android and iOS devices - you just have one virtual stick to rotate and walk forward + backward and a fire button. so you only hit the enemy if its on the same level +/- it's height... if you played doom you may noticed, that enemies in front of you but on a higher level are shootable. this is what i'm trying to archive the fastes way (performance side). sry if i'd not ponited out that clearly ;)

I will post how i did it when it works maybe there is a better way than what i'm dooing right now. or anybody can profit from it...

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by aldonaletto · Nov 02, 2011 at 10:18 PM

That's not an easy task with such limitations. Your idea is good, and I think it can be less expensive if you place all enemies in some user layer, than use Physics.CapsuleCast in this particular layer to find only enemies: CapsuleCast projects an imaginary capsule in the direction and distance specified, and returns the first collider hit, thus all you have to do is shoot the collider returned, if any.
Ideally, the volume cast should be pyramidal; to get something slightly more similar to this you could do a short CapsuleCast with a smaller capsule, and if nothing found do another CapsuleCast, this time with a larger capsule and starting where the smaller one finished.

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 CreativeStorm · Nov 02, 2011 at 10:32 PM 0
Share

This is great! I'd just know about Physics.SphereCast...

I was about to use a pyramidal mesh collider using trigger, but this would be two steps more including the distance check...

Using a capsuleCast i can shot up ... maybe 3 times - each time a bit taller. and the thing with the separate layer is great too. Thanks a lot - i'm on it :)

avatar image aldonaletto · Nov 03, 2011 at 01:04 PM 1
Share

Life would be much easier if Unity had a kind of Physics.PyramidCast!

avatar image
0

Answer by gfr · Nov 02, 2011 at 11:40 PM

Instead of casting, i think your approach could be modified (and should be inexpensive depending on the enemy-count/-density):
Keeping a list of enemies inside the collider attached to the player and then filter that one (e.g.: for those being within a certain horizontal angle from the reticule, shoot the center- & front-most of those).

With few enemies that should be rather inexpensive, but then again i haven't done measurements on those... Building a few test-cases (casts vs. book-keeping/filtering) and measuring how much time they take over a few hundred iterations should be relatively easy though.

Comment
Add comment · Show 5 · 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 CreativeStorm · Nov 03, 2011 at 01:39 AM 0
Share

That's an good idea as well - i will check this out tomorrow cause it's in the middle of the night here. I actually don't have many enemies on screen at once, but i have enemies spawning. This could be difficult to be combined. In addition i think there is a need of casting anyway because of cover/obstacles... best approach would probably be an mix to reduce the expensive stuff - thanks

avatar image aldonaletto · Nov 03, 2011 at 01:01 PM 0
Share

The best way to keep an enemy list is to let Unity do it for you: have an empty object called "Enemies", and any time you spawn a new enemy, child it to Enemies. You can iterate through all Enemies children to check if the enemy is visible (what means it's in the viewing angle), then check its position. This list is cheap because Unity keeps it up-to-date for you, deleting every destroyed enemy automatically.
Anyway, I suspect the CapsuleCast method is less expensive, because all calculations are done by internal routines written in C++ or other compiled language, which is much faster than .NET

avatar image gfr · Nov 03, 2011 at 01:16 PM 0
Share

Hm, i would have thought casting to be more expensive, but than again i don't know how the physics engine implements it. I guess i will have to test it myself when i have the time.
Good point on the enemy list.

avatar image aldonaletto · Nov 03, 2011 at 02:11 PM 0
Share

The enemy list approach isn't this cheap because you have to iterate through all elements, and if an enemy is inside the frustum (isVisible == true) and shooting angle, do a Raycast in order to make sure it's not hidden behind walls or other obstacles, then finally select the nearest enemy calculating the distances. $$anonymous$$aybe it's cheaper than the CapsuleCast, but only testing both alternatives we can be sure.

avatar image gfr · Nov 03, 2011 at 02:23 PM 0
Share

True, but the idea was that the angle-check should be rather cheap. If you're casting in a enemies-only-layer you'd also have to apply a visibility-check afterwards.

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Mobile Device Video Camera 1 Answer

testing on an android device 1 Answer

Mobile device textfield keyboard keyset - default to numbers 0 Answers

MOBILE - FPS Camera Rotation HELP 0 Answers

testing on an android device 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