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 /
This question was closed Sep 15, 2014 at 10:27 AM by galaboy for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by galaboy · Dec 19, 2013 at 11:24 AM · aiscriptingbasicsenemyai

enemy ai movement.

hi, am doing a space shooter game, in which i want the enemy to move in a zig zag movement, (i.e) it has to move forward and at the same time it has to move left and right. i have tried with physics, but this time i dont want to do it with physics. a basic outline of how to achieve will do great.

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 Gruffy · Dec 19, 2013 at 02:51 PM 0
Share

Waypoint translations $$anonymous$$eaning, you should develop a set of waypoints(transform or even just vector positions)...these should then be "Lerp`d" towards as your enemy object reaches the next current waypoint.

So, to keep it as a basic outline.... 1: Create an array of way points that can be iterated through. 2: Iteratively

 foreach(Transform waypoint in waypoints) 
 {
 
 transform.position = Vector3.Lerp(waypoints[i].localPosition.x,waypoints[i].localPosition.y, waypoints[i].localPosition.z, Time.deltaTime);
 }
 or 
 for(int i = 0; i < waypoints.Length; i++)
 {
 Vector3.Lerp(waypoints[i].localPosition.x,waypoints[i].localPosition.y, waypoints[i].localPosition.z, Time.deltaTime)
 }
 

Applying these way point positions as the translational goal for your enemy object.

You will need to check the enemy has both reached its current goal and is reassigned to position itself at the new one..

i write this and now have got a bee in my bonnet soam gonna quickly go into Unity.

BRB :)

But.....Read into what ive said here, try and implement it yourself first.

I will be online for a bit, so get back asap if you can buddy, we`ll try and solve this for you hey
Gruffy

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Gruffy · Dec 19, 2013 at 09:24 PM

Hey bud, here is a complete package that i put together.

It translates and rotates the object through a set of waypoints (you can move these to whereever, you like. have a play about with it and see what you come up with)

note: this uses quaternions also to rotate the object tracking the way points towards that waypoint`s local forward.

if you download the zip, unzip and add this custom package to a unity project and run the scene included, you will see the result.

I am guessing you will be wanting to create some sort of state system to handle your enemy AI for that i would create an empty parent(as can be found in the package scene)and i would prefab it out so that the scripts and way points are always inside (or childed) your enemy game object.

This way , when you create said FSM(or such like) when an enemy state was invoked or something like that, your enemy could just start patrolling the waypoints....until it saw you or something that might change its current state if ya get me (this is totally totally totally another subject though - FSMs i mean) Anyway, here`s package with scene and all code - enjoy and if you think it has helped you mark it an answer as i think this might help others too...especially as its a convenient package demonstration etc.

Below is a Link to a Dropbox folder where you can download the package as unity Answers doesn`t seem to be giving me any other options except to answer in text only, n all that.

LINK (copy below URL and paste in browser address bar to get to package)

https://www.dropbox.com/sh/hmn4ax6swykktf7/TuzjsQp-Un

LINK

Merry non-denominated holiday! Thanks for reading. Gruffy :)

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 Mayank Ghanshala · Sep 03, 2014 at 12:02 PM 0
Share

link doesn't work anymore

Follow this Question

Answers Answers and Comments

19 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

AI Enemy Follow Player 2 Answers

Enemy Follow AI problem 0 Answers

need help in the instantiation script 1 Answer

Character Animation won't work with FPS scripts 1 Answer

makeing enemies 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