Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Feb 13, 2016 at 08:15 PM by hexagonius for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by maewionn · Feb 12, 2016 at 02:08 AM · movementload level

[SOLVED] Gameobject wont move towards target with MoveTowards

Hello there!

[SOLVED]: Set Time.TimeScale at the end of the Spacelevel to 0, so that the Player can appreciate the text that gets displayed. Didn't think the timeScale would persist between levels, but it did. Thanks to all of you guys, for helping me keep the motivation up to find the issue!

So, I got a small galaxy scene setup, where I instantiate the players spaceship and on a rightclick, it moves towards the position of the mouse, until it is there.

For that, i use the following script in the gameobject:

 void Update(){
             if (Input.GetMouseButtonDown(1)) {
                 Camera mainCam = FindObjectOfType<Camera>();
                 target = mainCam.ScreenToWorldPoint(Input.mousePosition);
                 target.z = -1f;
                 
             }
             transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
 }

Which works fine. However, once I am at a galaxy system, I can enter the fight space there (which works fine to) and after that, I have a button pop in, which reloads the space scene.

Alas, once I got back into the space scene, the ship wont move. Everything in the setup seems to work. It correctly detects the player location, it detects where the mouse is and sets the target accordingly. However, my gameobject doesn't move anymore, even though, according to everything I see, it should.

Also, changing the value of float speed doesn't change anything either.

I am really stumped on this one. Please rush to my aid, fellow Scripters.

If I can provide any useful intel, just tell me.

Best Regards

EDIT: More Info. Using unity personal 5.3.1f1 and Application.LoadLevel. Also , there is a GUI Element which I move via rigidbody2D and add velocity. Strangely, this doesn't work after loading, either. On printing the MoveTowards, it return always the transform.position of the player, even if the target is different.

Comment
Add comment · Show 6
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 Guhanesh · Feb 12, 2016 at 10:22 AM 1
Share

If all scripts with $$anonymous$$oveTowards not working may be a Unity bug.Report to Unity.you can use Vector3.Lerp ins$$anonymous$$d and check if its working.

avatar image maewionn Guhanesh · Feb 12, 2016 at 03:56 PM 0
Share

Tried that, doesn't work either. Also, that doesn't explain the non-functioning of the GUI velocity, as that works with AddForce()...

avatar image wesleywh · Feb 12, 2016 at 04:36 PM 1
Share

Are you applying your scripts after the level loads? If your scripts are working but then stop working after the scene loads that seems to me like your not applying your scripts or something. Are they part of your prefab that you instantiate on scene load or are the scripts applied to already static objects part of the scene?

avatar image maewionn wesleywh · Feb 13, 2016 at 02:51 AM 0
Share

Hey wesleywh,

thanks for the help! The scripts are part of instances. Also, the scripts are working. Example: I got that button which adds force to a menu on the side, therefore sliding it in. After pressing play, that works. The fightscreen works to, then the level back to the galaxy map where said slider is, which has worked right after pressing play. If I print the force, it gets added to the rigidbody, but it doesn't move one bit.

Best Regards

avatar image TreyH · Feb 13, 2016 at 03:09 AM 1
Share

Did you assign a speed?

avatar image maewionn TreyH · Feb 13, 2016 at 05:05 PM 0
Share

Jup, also gets displayed fine.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

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

Related Questions

Calling a method twice in Start without overwriting 0 Answers

Character being pulled back when moving 0 Answers

how to randomly move each generated clone? 0 Answers

Spawned enemy walk from right to left destroying turrets. 0 Answers

FPSController does not work in Universal 10 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