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
1
Question by frame_th · Apr 30, 2012 at 04:41 AM · aitankcars

AI enemy vechicle problem

I want to know about script for control a tank. I can make it look at and follow player but I have some problem. the enemy tank don't see player it will move to straight and when it move to something such as a wall or bigstone it can't turn away from that object so the enemy tank will fools because it can't move to anywhere.

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
0

Answer by aldonaletto · Apr 30, 2012 at 05:10 AM

That's not an easy question - avoiding obstacles is a complex task. In this case, maybe you could use the following algorithm: each Update, cast a short ray forward; if nothing is hit, move the tank; if it hits something, enter a state where the tank will rotate a fixed angle (15 degrees, for instance) then return to idle state, where it will again verify obstacles ahead - something like this:

enum State {Idle, Chase, Attack, TurnLeft, TurnRight}; var state: State = State.Idle; var turnSpeed: float = 60; // 60 degrees per second var length: float = 8; // "see" 8 units ahead private var turnAngle: float = 0;

function Update(){ switch (state){ case State.Chase: // chase the player case State.Idle: if (!Physics.Raycast(transform.position, transform.forward, length)){ // move the tank forward if no obstacles ahead } else { // if some obstacle in range, enter turn right state: state = State.TurnRight; turnAngle = 15; } break; case State.TurnRight: // stay in turn mode until turnAngle ends: var dAngle = turnSpeed * Time.deltaTime; transform.Rotate(0, dAngle, 0); turnAngle -= dAngle; // when turnAngle ended, return to idle state: if (turnAngle

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

Answer by JamesArndt · Dec 22, 2012 at 07:42 PM

Latest tutorial upload for all of you Unity folks. This is a video that will help you get simple AI going in your racing or traffic games. The video includes a 1.4MB download of the entire Unity project seen in this tutorial (look in the video description).

http://www.youtube.com/watch?v=VbBY_jezoDI&feature=youtu.be

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

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

Multiple Cars not working 1 Answer

Traffic Script 1 Answer

Standard Assets/Car Waypoint Based: How to check if vehicle got to the last waypoint? 0 Answers

AI car script to follow a track 0 Answers

Lock rotation of object 4 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