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 oopoe · Dec 10, 2012 at 04:03 PM · enemychasesolid

Chasing Object Sinking

Hi,

I have an OBJ made in MakeHuman with a sphere collider that I want to follow my player when I come within a certain distance. I was helped out with a script that does this well. However my sphere which is inside my OBJ (a human) heads toward my character, but converges towards my FPS' feet, and in doing so, the feet of the object chasing me sink through the ground.

I have tried Rigidbodies, various colliders, character controllers all to no avail. Below is my script, attached to the OBJ. I suppose what I want is to fix the Y axis on the OBJ so that it stays at the same height. Either that or solidify the OBJ.

 // This is the object to follow
 
 var leader : Transform; 
 
  
 
 // This is the object which follows
 
 var follower : Transform; 
 
  
 
 // This is the speed with which the follower will pursue
 
 var speed : float = 2.0;
 
  
 
 // This is the range at which to pursue
 
 var chaseRange : float = 10.0;
 
  
 
 // This is used to store the distance between the two objects.
 
 private var range : float; 
 
  
 
  
 
 function Update(){ 
 
 
  
 
    // Calculate the distance between the follower and the leader.
 
    range = Vector3.Distance( follower.position,leader.position );
 
  
 
    if ( range <= chaseRange ){
 
  
 
       // If the follower is close enough to the leader, then chase!
 
       follower.LookAt(leader); 
 
       follower.Translate( speed * Vector3.forward * Time.deltaTime); 
 
  
 
    } // End if (range <= chaseRange) 
 
     
 
    else { 
 
  
 
       // The follower is out of range. Do nothing.
 
       return;
 
  
 
    } // End else (if ( range <= chaseRange ))
 
  
 
 } // End function Update()
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 TheDarkVoid · Dec 10, 2012 at 05:57 PM

I think you should add an empty gameObject to your character that is higher and set that as te leader

Comment
Add comment · Show 3 · 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 oopoe · Dec 10, 2012 at 06:36 PM 0
Share

Thanks man that worked perfect, just stuck a sphere above the camera and set that as the leader.

Appreciate the help.

avatar image TheDarkVoid · Dec 10, 2012 at 09:24 PM 0
Share

no problem, happy to help

avatar image himanshu619 · Dec 27, 2012 at 02:18 PM 0
Share

How to add bouncy effect to this following object while it collide with other game objects (other then your player).

avatar image
0

Answer by Jake.OConnor · Dec 10, 2012 at 06:12 PM

It would appear that the center of your "leader" is at the foot of the object. When you call LookAt it is orienting the follower towards whatever the center of leader is and then you're heading towards it. Highlight the "leader" in the inspector and look at where the position gizmo shows up, this is where the follower is going to be pointing towards. If it is at the foot then that is the problem, and you can add an empty dummy GameObject to your leader's heirarchy to denote the center. Once you have that, use that in the LookAt() function.

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

12 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

Related Questions

Problem using boids algorithm for chasing enemies. 1 Answer

Getting the player to retreat a certain distance from the player 1 Answer

Enemy AI Problem 0 Answers

Solid enemy help 1 Answer

Enemy raycast chase player 0 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