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 MkSv · Mar 23, 2013 at 06:21 PM · collisionai

Need AI script that makes object follow the player (and collidors work)

I have this code till now,

 var target : Transform; //the enemy's target
 var moveSpeed = 3; //move speed
 var rotationSpeed = 3; //speed of turning
  
 var myTransform : Transform; //current transform data of this enemy
  
 function Awake()
 {
     myTransform = transform; //cache transform data for easy access/preformance
 }
  
 function Start()
 {
      target = GameObject.FindWithTag("Player").transform; //target the player
  
 }
  
 function Update () {
     //rotate to look at the player
     myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
     Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
  
     //move towards the player
     myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
  
  
 }
Comment
Add comment · Show 2
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 dfghdh · Mar 23, 2013 at 07:35 PM 0
Share

I think you answered my question too, thanks :) If you go and post an answer ill up vote :)

http://answers.unity3d.com/questions/423222/question-about-enemy-ai.html

avatar image SkilledAssassin6 · Mar 23, 2013 at 07:41 PM 0
Share

Thanks so much! I was just about to ask this question!

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by AlucardJay · Mar 23, 2013 at 06:55 PM

I have made videos on exactly what you are asking. Your script is exactly like at video 23 :

  • 23 _ NPC 1-1 : Moving : http://youtu.be/p9yLZmgkFWY

  • 24 _ NPC 1-2 : Colliding : http://youtu.be/7di6FnR7rqU

  • 25 _ NPC 1-3 : Grounded and Turning : http://youtu.be/78a1VSaaDuo

  • 26 _ Raycasting Basics : http://youtu.be/Sj4oxfQqzhA

  • 27 _ NPC 1-4 : Basic Obstacle Avoidance : http://youtu.be/JlulRhjLsNY

  • 28 _ NPC 1-4a : Basic Obstacle Avoidance : http://youtu.be/szxB6RBhVyQ

And I have just taken a break from recording more videos to see your question. So check out all my videos on Programming and Making Games with Unity 3D : http://www.youtube.com/channel/UCKO90x3pGUgpOjhV-HhWVIw/videos?view=1&flow=grid

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 AlucardJay · Mar 23, 2013 at 07:39 PM 1
Share

If you want some written explanation, here is the answer that I wrote, then is adapted in my rigidbody character controller videos. Don't forget to read the comments about adding the isGrounded variable with the collision events, but it's all in the videos, hope you find them useful : http://answers.unity3d.com/questions/406685/my-enemies-merge-when-they-come-towards-me.html

avatar image MkSv · Mar 24, 2013 at 06:34 AM 0
Share

Thanks so much ! I am gonna watch all your videos!

avatar image AlucardJay · Mar 24, 2013 at 08:35 AM 0
Share

Hi again $$anonymous$$kSv, as I just posted on youtube : I am really very sorry but there have been too many times where someone just copy-pastes, then hits play, then post a new question here saying 'it doesn't work'.

This is no reflection on you, am really glad that you might find my videos useful. But I cannot post my scripts here anymore. So the few have really ruined it for the many :( I could show you so many many UA questions where this has happened, and it has driven me a little bit mad!

If you are having problems and are really stuck, then you are most welcome to come over to one of my forum pages. There I am very happy to help with any problems you are having. Here are the links to the forum pages :

  • forum.unity3d.com/threads/172415-Slender-Guide-by-alucardj

  • http://forum.unity3d.com/threads/173876-Program$$anonymous$$g-and-$$anonymous$$aking-Games-with-Unity-3D

Again, if there are any problems at all, please just visit on of the forum pages, and I am most happy to answer any question. Am glad you posted this comment, I could give you much more detail than in a youtube comment! All the best, am really happy to have you watching, and hope to see you in the forums =]

avatar image Chronos-L · Mar 24, 2013 at 08:52 AM 0
Share

@alucardj, I just read the forum thread on program$$anonymous$$g and making games with Unity. You sir, have gain my salute and respect. You have some serious contributions to the community. I will go through all the videos in the forum and learn something new from there.

avatar image AlucardJay · Mar 24, 2013 at 08:57 AM 0
Share

heh, thanks so much dude, its the comments like yours there that just gives me a big smile and makes my day, awesome. Wow, yes, I am not just complaining about 'the problem' (you know what I mean here from my other UA comments), but am really trying to do something about it. There are just not enough hours in the day!

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

14 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

Related Questions

Why is my AI not thinking the collisions fast enough? 1 Answer

Enemy Ai Problem with the collider and gravity 1 Answer

NavmeshAgent vs Character Controller = Absolute Unity Failure? 1 Answer

Jittering movement when colliding with object 1 Answer

Have falling object exit from a collider after collision? 2 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