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 Tinker55 · Dec 04, 2010 at 10:44 PM · rotationairandom

Random movment, like mobs in wow

I want to make my enemy character to get a random rotation, then move for about 3 sec, then stay get a new rotation and move again. And keep doing that until the player comes in range.

Here is my code:

function Idle() { while(true) { if(dist > awareDist) { randRotation(); yield WaitForSeconds(5); walkRandom(); yield WaitForSeconds(5); } } }

function randRotation() { transform.rotation = Quaternion.AngleAxis(Random.Range(-40,40), Vector3.up); }

function walkRandom() { var forward : Vector3 = transform.TransformDirection(Vector3.forward); var controller : CharacterController = GetComponent(CharacterController); controller.SimpleMove(forward * speed); }

The Idle function is called from Start. Animations will be added. dist is the distance to the palyer.

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
0

Answer by Justin Warner · Dec 05, 2010 at 02:31 AM

http://answers.unity3d.com/questions/30008/random-direction

Also, you can go off: http://answers.unity3d.com/questions/203/how-to-generate-a-random-number-inside-unity

Get a switch statement, and each case, have it do a certain action, maybe 1,3,6,8 all rotate accordingly; 10,30,90,130 degrees, then 2 and 7 move the object forward accordingly; 5 units, 10 units, and numbers 4 and 9 just pause for the 2 second yield in between...

Or you could make multiple functions, randomly chooses a function, and that function has a script that uses coroutines that make the character return to its original spot as if it doesn't it could fall off the cliff... lol

But yeah, 3 ways to go about it.

Search next time.

=)

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

No one has followed this question yet.

Related Questions

Can you randomise a Navmesh agents rotation 1 Answer

How to exclude int values from Random.Range? 2 Answers

Z rotation locks to certain value randomly? 0 Answers

Make AI walk around randomly until Player is Seen. (C#) 2 Answers

My Zombie Model is coming at me sideways with the AI 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