Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
2
Question by Awia · Oct 24, 2011 at 10:01 PM · objectmovemovingtowards

Moving an Object towards another Moving Object

HI
How do I move an object (particle-emitter) towards the player who are most certainly moving around? I have no idea on how I should do this, and I could not find an answer to this in the answered questions.
My game is made in c#, and I'm pretty new to programming so be nice :D

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 Casper091 · Aug 25, 2013 at 07:15 AM 0
Share

$$anonymous$$y object to move is lifting off the ground to get to target, and when i add a rigidbody, it makes it fall over and glitch/bug

avatar image robertbu · Aug 25, 2013 at 07:17 AM 1
Share

@Casper091 - If you have a problem, please open a new question. Your comment is not related to this question. I'll be deleting your comment shortly.

avatar image ETech-Studios robertbu · Jun 24, 2016 at 03:40 PM 0
Share

@robertbu you never did...

2 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by aldonaletto · Oct 24, 2011 at 10:23 PM

You must repeat the same sequence at each Update: get the target position, then move the object in the target direction a small distance proportional to the desired speed and to the time elapsed since the last frame (Time.deltaTime). The easiest way to do that is with Vector3.MoveTowards (badly explained in the docs):

Transform target; // drag the player here float speed = 5.0f; // move speed

void Update(){ transform.position = Vector3.MoveTowards(transform.position, target.position, speed*Time.deltaTime); } Vector3.MoveTowards(from, to, distance) returns a point in the line from-to distant distance units from the the from point. The distance parameter is internally clamped to never return a point ahead the to point.
NOTE: This script must be attached to the particle object.

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
avatar image
0

Answer by freeclup · May 31, 2013 at 08:10 AM

just attache object and set target

 #pragma strict
   // drag the player here
 var  speed:float = 5.0f; // move speed
 
 function Start () {
 
 }

 function Update () {
  transform.position = Vector3.MoveTowards(transform.position, Vector3(32,15,-92),   speed*Time.deltaTime);
  
 }
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 Rocketman123 · Dec 23, 2016 at 08:23 PM 0
Share

Hey. i don't mean to be mean (no pun intended) but Awia asked for C#. Thats Javascript. Just sayin'

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

8 People are following this question.

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

Related Questions

Move the player towards the cube to attack. 0 Answers

How do I move an object from point A to point B using a trigger? 3 Answers

Move object A towards object B 2 Answers

What am I doing wrong? 1 Answer

Move Object A towards Object B at a definite speed 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