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 post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by UnLucky · Jun 25, 2012 at 12:01 PM · beginnersbehaviorfunctional-reactive-programming

I'd like to make my object chase another one of my objects.

Hello everyone,

I have just tried to do just the one function: There is one target object. I am moving the object in runtime.

There's another object which should chase the aforementioned object.

It should, let us say colourfully, "catch" the target object if the objects touch. If caught, the target object, she will be completely destroyed with a dramatic flourish. That's the concept in a nutshell.

But now .. as so often in life ... the problem...

My problem, the hunted object is moving but the hunter-object is not moving correctly.

Can anyone help me do this? Thanks!

Comment
Add comment · Show 3
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 UnLucky · Jun 25, 2012 at 01:05 PM 0
Share

@Fatti hey do know this?

avatar image AlucardJay · Jun 25, 2012 at 01:14 PM 2
Share

Without posting the script you are having trouble with, there won't be much help. Code is like lego : the bricks are standard, but what a person makes with them is pretty much unique.

avatar image aldonaletto · Jun 25, 2012 at 01:17 PM 1
Share

@alucardj is right: we should see your script in order to help you (our telepathic powers aren't good enough to visualize your script!)

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by aldonaletto · Jun 25, 2012 at 01:15 PM

You should post your script - how could we help without seeing it? Anyway, the basic idea is: calculate the target direction and move towards it - something like this:

var target: Transform; // drag the target here, or "GameObject.Find" it at Start var chaseSpeed: float = 5;

function Update(){ var dir = target.position - transform.position; // get the target direction var dir.y = 0; // keep it strictly horizontal var vel = dir.normalized chaseSpeed; // calculate the velocity vector // the way you will actually move depends on your character's nature: //- If it's a simple object (no Rigidbody, no CharacterController): transform.Translate(vel Time.deltaTime, Space.World); //- If it's a CharacterController (SimpleMove includes gravity automatically): GetComponent(CharacterController).SimpleMove(vel); //- If it's a Rigidbody (not recommended: rigidbodies are too wild!): vel.y = rigidbody.velocity.y; // keep the rigidbody gravity rigidbody.velocity = vel; }

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 AlucardJay · Jun 25, 2012 at 01:23 PM 0
Share

I was just typing up a transform.LookAt(target) and transform.position += transform.forward x speed x Time.deltaTime , but you have given much more helpful info =]

avatar image UnLucky · Jun 26, 2012 at 06:36 AM 0
Share

@Aldo Naletto its working perfectly... Thanks..

avatar image sandybites · May 18, 2014 at 01:06 AM 0
Share

Can someone post a C# version of this? Thanks!

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

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

Lifebars not appearing above enemies' heads 3 Answers

My Y position goes fixed to some value 0 Answers

How to fix a specific colliders count problem 2 Answers

How to import the object from server to unity 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