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 chrishall · Dec 06, 2013 at 10:28 AM · animationwaypointwaypointswaypoint system

How to play an animation with waypoints

Hi there I am creating an underwater game, and I have set up a waypoint system for a fish model. The waypoint script works okay, but the fish is facting the wrong direction when it moves. So I added a simple animation to it, now it does not move. How can I have the fish move in the waypoint system and still have the animation play?

Here is my script: var waypoints : Transform[]; private var current_waypoint : int = 0; var speed : int = 10; function Update () { var target: Vector3 = waypoints[current_waypoint].position; var moveDirection : Vector3 = target - transform.position; if(moveDirection.magnitude < 2) { current_waypoint++; if(current_waypoint >= waypoints.length) { current_waypoint = 0; } } else { rigidbody.velocity = moveDirection.normalized * speed; } transform.LookAt(waypoints[current_waypoint]); }

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by GameVortex · Dec 06, 2013 at 10:43 AM

If all you want is to have the fish face the correct direction you could make a new GameObject that will be the root, add your current fish gameobject as a child to that root GameObject and move the fish component to the root instead. Now you can rotate the Fish GameObject to face the correct direction while the Fish component moves the root itself.

If you still want to use an animation, just do the exact same thing as above, but have the animation play on the Fish GameObject while the Fish Component moves the Root. This way the animation does not overwrite the transform changes you do in the Fish script.

Comment
Add comment · Show 5 · 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 chrishall · Dec 06, 2013 at 11:26 AM 0
Share

Thanks! I am still a little confused though, what do you meant by root?

avatar image GameVortex · Dec 06, 2013 at 12:28 PM 0
Share

Sorry, I was rambling a little. =P Root is just the name of the new GameObject. It does not have to be named Root though.

Step by step:

  1. Create GameObject named "Root".

  2. Add Fish GameObject as child of Root.

  3. $$anonymous$$ove Fish Component from Fish GameObject to Root GameObject.

  4. Rotate Fish GameObject so it faces the correct way.

avatar image chrishall · Dec 06, 2013 at 01:42 PM 0
Share

Oh okay, but the fish is only made from one model, there is no children on the fish model. What do you mean by fish component? Sorry hah I am still new :(

avatar image chrishall · Dec 06, 2013 at 01:48 PM 0
Share

Yay! Don't worry I have got it to work! Thanks so much for the help!!

avatar image GameVortex · Dec 06, 2013 at 02:11 PM 0
Share

Glad it worked out for you. =)

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

17 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

Related Questions

How do you move a character to another waypoint after landing on a specific waypoint 1 Answer

Making users able to make custom tracks to follow by the character in the game 0 Answers

How will i make my objects/model(say a car) face the way points and travel towards it,instead of blindly following it? 2 Answers

Getting script to update list of transforms when destination reached or the transform's game object is inactive 0 Answers

waypoint system help 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