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
0
Question by HumanError · Dec 22, 2012 at 07:41 PM · shootaimobstacle

Aim and than shoot

I made some turrets for my game, each one can find me and it will start shooting when I get into it's shooting range.

The problem is that the turrets are shooting even if it not "aming" on me, it will shoot as long I'm in it's shooting range: for some the damping speed not allow them to always aim on me and it take some time untill thay are "realy aim" (it have to be like that), but thay will continue to shoot because the distance between me and the turrets allow it. The turrets will continue to shoot even if there is an obstacle like a wall or another turret between us from the same resone.

How do I make the turrets shoot only if thay are aming at the general direction (for missing chances) of me and when there is no obstacle between us?

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Maulik2208 · Dec 24, 2012 at 08:39 AM

Follow the syntax showed below.....

Physics.SphereCast(/here fill as per your requirement/);

This is the simple way for your need.....Cheers......Enjoy......If found useful Don't forget to mark......

Comment
Add comment · Show 1 · 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 HumanError · Dec 24, 2012 at 09:50 AM 0
Share

Ahh, I didn't thout this is a code... I still not sure how to fill it: I noticed "radius", which meen the turret's range, direction meen things like "forward" or "right", and this is it... How do I fill it as my requirement?

avatar image
0

Answer by cagezero · Dec 22, 2012 at 09:16 PM

Use Physics.SphereCast. Set the radius to be your auto aim error, distance to be the range of your turret.

         //Ray should be configured with the turrets position and whatever 
         //direction it is currently pointing (assuming Vector3.forward).
         Ray = new Ray(turretRange.transform.position, Vector3.forward);
         
         if(Physics.SphereCast(ray, autoAimError, hitInfo, turretRange)) {
             
             //There are various ways to tell if this is the right collider.
             //Here we will use the tag of the object we want to hit.
             if(hitInfo.collider.gameObject.tag.CompareTo("target")) {
                 
                 //The sphere cast hit the target. Shoot.
             }
             else {
                 
                 //The sphere cast missed the target. Don't shoot.
             }
         }
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 HumanError · Dec 24, 2012 at 08:22 AM 0
Share

Sorry, I don't have this option... I have SphereCollider, not SphereCast...

avatar image cagezero · Dec 24, 2012 at 08:48 AM 0
Share

Use Physics.SphereCast from your turret. Once it detects that "you" are in range (using the algorithm you previously mentioned) you can begin to sphere cast from the turret to "you". This assumes that the sphere collider is attached the object that the turret is ai$$anonymous$$g at. If this is not the case please provide more details.

avatar image cagezero · Dec 24, 2012 at 10:51 AM 0
Share

http://docs.unity3d.com/Documentation/ScriptReference/Physics.SphereCast.html

avatar image HumanError · Dec 26, 2012 at 10:29 AM 0
Share

I don't understnd it yet. That what I did so far:

Physics.SphereCast(GameObject, 250, Vector3.forward,

I don't know how to continue and I don't understand what HitInfo meens.

avatar image cagezero · Dec 26, 2012 at 04:25 PM 0
Share

Added some pseudo-code to the answer.

RaycastHit hitInfo contains information about what the sphere cast collided with. Use it to check if the turret has line of sight to the target (did the sphere cast hit the targets collider).

http://docs.unity3d.com/Documentation/ScriptReference/RaycastHit.html

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

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Enemy Aims at Player's Current Position 1 Answer

Bullet shots direction player is facing, cant shoot in diagnal or up 2 Answers

how do I shoot where my cross hair points? 0 Answers

Aim to crosshair? 3 Answers

3rd Person Gun Aim 1 Answer


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