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 Tobias · Jun 23, 2010 at 02:32 PM · waypointnpcmonster

How to move a object to my position?

Hello I want an object (Monster/Npc) to rotate to my player and move to me, when I'm too close to it.

So my questions:

  • How to check if I'm close enough to the monster (Aggro Range)
  • How to let the monster move to my position (Walking to me, not porting).
  • How to make the monster walking to specific waypoints?

I know that theres allready a waypoint script, but the problem is, that I cant choose which monster is using which waypoints, instead the monsters use the waypoints that are closest to them.

Thank you very much

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
Best Answer

Answer by AnaRhisT · Jun 23, 2010 at 02:55 PM

  • how to check? while(Vector3.Distance(yourMonsterName.transform,transform.position) > 2)

  • rotate + move

    var rotationSpeed : float = 0.2; var direction : Vector3 = transform.position - yourMonsterName.position; while(Vector3.Distance(yourMonsterName.position,transform.position) > 2) { transform.rotation = Quaternion.Slerp(transform.position,Quaternion.LookAt(direction), rotationSpeed* Time.deltaTime); transform.eulerAngles = new Vector3(0,transform.eulerAngles,0); yield;

    }
    

    it was above how to rotate, now how to move?

    while(Vector3.Distance(yourMonsterName.position, transform.position) > 2){ //animation.CrossFade("walk"); //if u have animation @walk var controller : CharacterController = GetComponent(CharacterController); // reference the CharacterController to controller var direction : Vector3 = transform.position - yourMonsterName.position;

             controller.SimpleMove(direction.normalized * speed);
             yield;
    
    

    }

    Also , I'm not but this: var direction : Vector3 = transform.position - yourMonsterName.position; can be changed to this: var direction : Vector3 = yourMonsterName.position - transform.position;

    1. add this script to ur enemy (it must have character controller though)

    http://09duck.pastebin.com/2DCZXt4M

    open the waypoint slot in the monster's inspector and add 3 waypoints gameobjects to it.

    so u may ask how to create a way point and recognize it in inspector?

    so paint a simple circle in ur Paint program and it to unity's project, open a folder called "Gizmos" it's case sensitive btw! so make it as written in quotation marks,add the picture to it, make sure u saved the picture as jpeg/jpg format! and make sure the picture is called "waypoint"!

    add this script to ur waypoint gameobject : http://09duck.pastebin.com/LYpj7aLW so now u'll see ur waypoint with a picture, now u can attach all ur 2,3,4,5,6 or how many u want to ur waypoint. the script is designed to work on 3 waypoint, but u can simple make it 4,5,6,7 by changing this line :

    if(currentWaypoint == 3){ currentWaypoint -= 3; }
    

    to like:

    if(currentWaypoint == 5){ currentWaypoint -= 5; }
    

    which means 5 waypoints, when it reaches the 5th it goes to the first one.

    Comment
    Add comment · Show 9 · 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 Tobias · Jun 23, 2010 at 03:00 PM 0
    Share

    Wow thanks, perfect answer.

    Little question: What is "your$$anonymous$$onsterName"? A prefab?

    avatar image AnaRhisT · Jun 23, 2010 at 03:05 PM 0
    Share

    var Aggro :Transform; for example..

    avatar image Tobias · Jun 23, 2010 at 03:08 PM 0
    Share

    I have another little problem

    The npc is moving to the waypoint, but it never reach it! Its getting slower and slower and then he just stands there

    avatar image AnaRhisT · Jun 23, 2010 at 03:10 PM 0
    Share

    getting slower means : speed = Random.Range(0.8,1.31); u can make it like speed = Random.Range(10,20); also u can check to see if gets closer with that: if(moveDirection.magnitude

    avatar image Tobias · Jun 23, 2010 at 03:16 PM 0
    Share

    Ive found the error, the cube never reaches the waypoint because the waypoint is too heigh (y-axe).

    Is it possible to ignore the heigh?

    Show more comments
    avatar image
    0

    Answer by clip911 · Jun 15, 2011 at 04:21 AM

    i got another question. i want to move an object e.g like a cube , randomly into a limited space like position.x = Random.Range(-4,4) position.y = Random.Range(-4,4) but as we know position does not translate the object its just snap to the position

    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 TetchedOne · Nov 16, 2012 at 03:21 PM 0
    Share

    Look at this http://docs.unity3d.com/Documentation/ScriptReference/Transform.Translate.html

    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

    2 People are following this question.

    avatar image avatar image

    Related Questions

    The name 'Joystick' does not denote a valid type ('not found') 2 Answers

    What's causing my NPC Controller to invert? Please Help!! 0 Answers

    How do I add NPCs? 2 Answers

    NPC Waypoint Choice 0 Answers

    Problem with MoveToWaypoint 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