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 ThatUnityNoob · Jul 17, 2012 at 02:18 PM · raycastaienemy

Enemy AI Running Through Wall With Raycast

Hi!

I have an enemy AI who wanders around my world with random waypoints and when he incounters an object that isn't the player, he dodges it to get around it and keeps going. He also sends out rays to tell if he can or cann't see the player. If that script comes back true, (So he sees the player) he stops wondering and starts "attacking" by moving at the player in a faster motion. Also, if the player isn't behind anything, (wall) he will start firing at the player. But if the player goes behind a wall or something, the enemy stops firing and keeps running at the player. Then when he incounters the wall, he dodges it. Heres the problem. While the enemy is dodging the wall, he is still locked on to the player. So if the player keeps running farther and farther away, the enemy while stop dodging and just lock onto the player and run straight at him through the wall. Any ideas? Comment if you need more information...THANKS!

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

1 Reply

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

Answer by DoctorWhy · Jul 17, 2012 at 05:44 PM

Is the AI script written by you? If so, it seems more like a problem with the script, and not a problem that we can understand without a code example.

Have you tried running the code through the Debugger, and putting a break point where the AI should be dodging a wall, but is deciding not to? If you don't know how to use the debugger, I would recommend learning how because it will save you hours of searching for the issue. This looks like a good place to start http://docs.unity3d.com/Documentation/Manual/Debugger.html . The debugger is very similar to other debuggers I used, so if you ever debugged any code, then you should be able to figure this one out.

Comment
Add comment · Show 11 · 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 ThatUnityNoob · Jul 20, 2012 at 10:26 PM 0
Share

I have never used a debugger before but it sounds very useful! I didn't need to use it to figure out what needs to be done though. I have got to the point where all I need is a little code telling my AI to go to the position of the player BEFORE he lost sight of him (So where the player was before he went behind "cover"). Any ideas? THAN$$anonymous$$S!

avatar image DoctorWhy · Jul 20, 2012 at 10:55 PM 0
Share

It is hard to say depending on how your AI is programmed. If you are passing it the player and it is using the player position to go to (the gameObject.transform.position), it can just save the players last known position then move to that position using the same chasing logic it would for the player. But again, it depends on how the AI is programmed.

avatar image ThatUnityNoob · Jul 20, 2012 at 11:13 PM 0
Share

Right right. I wrote the AI script myself. What happens is when the player goes behind "cover" the enemy chases after him still. What I would like is for him to stop chasing the player but start "chasing" the last known position of the player before he went behind "cover. By the way, how can I make my AI save the players position before he "lost him"? If you can tell me that I can get the rest...THAN$$anonymous$$S!

avatar image DoctorWhy · Jul 20, 2012 at 11:19 PM 0
Share

Just save a class scope Vector3, e.g. "LastPlayerPosition", of the known player every Update() and use that LastPlayerPosition to do the moving logic ins$$anonymous$$d of the player's transform.position. Then, just don't update the position if the AI can't see the player, and the AI will run to the LastPlayerPosition ins$$anonymous$$d of the player's transform.position.

avatar image ThatUnityNoob · Jul 20, 2012 at 11:31 PM 0
Share

OH! Ok. I see exactly what to do know. Well, all but one thing...What is the code to save a vector 3 position. That is all I need and I'm good. Thnaks for all the help!

Show more comments

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

[SOLVED] using var from another method? 2 Answers

How to stop enemy shooting through wall 1 Answer

How to Stop Enemy "Shooting Through A Wall" 1 Answer

enemy raycast to detect player 1 Answer

Enemy to move out of way of player 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