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 Alexandre Auger · Mar 02, 2012 at 05:26 AM · gameobjecttranform.position

Make a game object move towards another object and continue its path.

I dunno if the title is clear enough.

I want a game object to move towards another game object but once it reaches the object i want it to continue on its path in the same direction/alignment. I have been trying to find a way to do this for a while now and i am stuck.

thanks

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 Blazor Ramone · Mar 02, 2012 at 05:41 AM 0
Share

How are you moving the object? Is it a rigid body with forces applied or are you doing a translate?(code sample?)

Is the target game object also moving? $$anonymous$$eaning are you intending to continuously update the direction of movement toward the target object?

How are you deter$$anonymous$$ing when the object reaches the other object? collision? matching positions?

avatar image Alexandre Auger · Mar 02, 2012 at 03:26 PM 0
Share

i am moving it using translate.

all i want is to get the position of the target object and move the other object towards it and making it continue its path after it reaches the target object.

what i mean by when it reaches the target object. is all i want is the other object to move in the direction of the target object but during that time the target object will move and not stay there.

Think of it has a gun shot and someone moves out of the way but the gunshot doesnt stop it continues until it reaches a wall or something. thats what i wanna replicate.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Mar 02, 2012 at 04:50 PM

Supposing you want to use Update, and the object will start moving when "Fire1" is pressed, you can use the script below (attached to the moving object):

var target: Transform; // drag the target here var speed: float = 5.0; // object speed private var moving = false; // object initially stopped private var dir: Vector3;

function Update(){ if (Input.GetButtonDown("Fire1")){ // if Fire1 pressed... dir = target.position - transform.position; // calculate the target direction... moving = true; // and enable movement } if (moving){ // if movement enabled... // move the object in the calculated direction (world coordinates): transform.Translate(dir speed Time.deltaTime, Space.World); } } The object will start moving in the target object when Fire1 is pressed. The object will continue moving in the same direction, even if the target has moved from there. If Fire1 is pressed again, the object will turn to the new target direction and continue moving.

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 Alexandre Auger · Mar 02, 2012 at 05:53 PM 0
Share

worked perfectly Thank you

avatar image
0

Answer by WaleedAzam · Aug 17, 2014 at 02:23 PM

http://www.youtube.com/watch?v=VcNly-cMZV4

http://www.youtube.com/watch?v=mP7ulMu5UkU

You will definitely find the answer these are just 4-5 minute clips.

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

7 People are following this question.

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

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

scaling plane gameobject to fit orthographic view iphone unity3d 0 Answers

Continually Updating position of Instantiated Object (to Mouse Pointer) 0 Answers

DontDestory gameobject doesn't work on button click after a new scene loads 2 Answers

Unity Detonator Problems 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