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
-1
Question by superluigi · Jun 15, 2013 at 09:53 PM · javascriptlookat

lookat not updating my position(somebody out there has to know the answer)

This script is attached to my flyingEnemyPrefab. I have two cubes instantiating the flyingEnemy and this script makes the enemy fly to my location but when I move the enemies keep flying to my first location. The cubes are children of my player so they move along with me. If I walk to one side far enough and place the cube on top of my first location the enemies are literally flying straight down. I need for every new flying enemy that's instantiated to fly to my current location at the point of its instantiation.

 var player : Transform;
 var moveSpeed = 5;
 var minDist = 0;
  
 function Update () 
 {
     transform.LookAt(player);
     if(Vector3.Distance(transform.position,player.position) > minDist)
     {
     transform.position += transform.forward * moveSpeed * Time.deltaTime;
     }
 }
Comment
Add comment · Show 4
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 Kirbyrawr · Jun 16, 2013 at 01:33 AM 0
Share

I tested it and it works perfectly, what's it's your problem?

avatar image Kirbyrawr · Jun 16, 2013 at 02:07 AM 0
Share

Oh that's a good notice, i did it so that's why i asked that xD

avatar image robertbu · Jun 17, 2013 at 04:53 AM 0
Share

I read your question before, and did not understand the problem. If all these cubes are really children, then perhaps you want to change transform.localPosition...and move towards a local position of (0,0,0).

avatar image superluigi · Jun 17, 2013 at 06:29 PM 0
Share

robertbu the cubes are children of my player so that they travel with him. They are invisible in fact I can replace them with an empty gameobject. This script is attached to the flying enemy that they instantiate. A flying enemy gets spawned once every 3 seconds but they always but even if I move the flying enemies continue flying to my first location.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Jun 17, 2013 at 07:12 PM

I'm assuming you want the cubes to move towards the player/parent. You can use something like:

 transform.localPosition = Vector3.MoveTowards(transform.localPosition, Vector3.zero, moveSpeed * Time.deltaTime);
Comment
Add comment · Show 2 · 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 superluigi · Jun 17, 2013 at 09:28 PM 0
Share

no the cubes are fine where they are they are children of my player so they stay at the distance they are at. There's one on my left and one on my right. They both have a script that instantiates flying enemies. $$anonymous$$y problem is this script(above), this one isn't attached to the cubes it is ins$$anonymous$$d attached to my flying enemy prefab. The flying enemies keep flying to the location $$anonymous$$y player starts in but when I move my player they continue flying to the first location ins$$anonymous$$d of updating my location when I move.

avatar image robertbu · Jun 17, 2013 at 11:15 PM 0
Share

Your code above is straight forward, and should work. Add a Debug.Log() statement in the Update() loop:

 Debug.Log(player.position);

If this is not changing, then you've not initialized 'player' correctly.

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

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

Related Questions

Follow up to AI Pathfinding Question 0 Answers

Rotate character to the moving direction problems? 2 Answers

hoe to rotate a AI as a animation 1 Answer

LookAt not working, points in wrong direction. 1 Answer

Arm Look At script Issues (javascript) 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