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 PrimeDerektive · Jan 10, 2011 at 01:28 AM · animationmovementcharactercontrollertopdown

Best way to handle animations on my top-down shooter setup?

I've been mulling over this for a while now, and can't think of a solution.

I have a top-down shooter prototype set up where the root object of the character has the CharacterMotor/Controller, and FPSWalker script on it. The character model itself (with the animations) is a child of this, with a LookAtMouse script on it (this is the only way I could figure out how to do the traditional top-down shooter/twin stick control setup, where you can look/shoot in one direction and move in another). The camera is simply in the scene, with a script that targets the player object, and looks at it from an offset above.

My problem is, I have 4 animations: run, two 45 degree angle runs (running at an angle both left and right), and two side-run animations (left and right). I can't for the life of me figure out how I should determine which animations to play and when.

I was going to try basing them off of normalizing the character controller velocity.x and z, but that would only work if it was the character controller was also the object with my LookAtMouse, and if I do that, the controls get all backwards when you're looking in the wrong direction.

Obviously I can't just base them on the horizontal/vertical input axes, because you could, for example, be moving forward with the vertical input axis but looking in a different direction.

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

2 Replies

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

Answer by Paulius-Liekis · Jan 10, 2011 at 07:39 AM

If I undestood what you need correctly then I would do something like this:

Vector3 velocity = get_it_from_somewhere; // look world space direction Vector3 lookDirection = lookAtComponenetTransform.forward; float angle = Vector3.Angle(velocity, lookDirection); // IIRC, angle will be always positive from 0 to 180, so we need to figure out side as well bool right = Vector3.Dot(lookAtComponenetTransform.right, velocity) > 0;

if (right) { if (angle < 20) // play run forward else if (angle < 60) // play diagonal run right else // play right run } else { if (angle < 20) // play run forward else if (angle < 60) // play diagonal run left else // play left run }

You could also blend between each pair depending on angle...

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 PrimeDerektive · Jan 10, 2011 at 01:41 PM 0
Share

Wow, that looks great... still trying to comprehend it though as i don't have unity in front of me right now. A few questions: I want to store the CharacterController velocity on from the parent object (the "move" object, not the "lookat" object) in that velocity var, right? Also, what if I want to have reverse versions of all those animations as well, for when hes moving backward (relative the lookat's transform forward)?

avatar image PrimeDerektive · Jan 11, 2011 at 04:21 AM 0
Share

After some tinkering I figured it out. Thanks!

avatar image
0

Answer by tylo · Jan 10, 2011 at 01:38 AM

I think you should have one run animation, and that your rotate your player to fit the direction you want to run in.

You would play your run animation whenever the movement stick was active, and you would calculate a heading that your character is moving towards. Finally, you would Slerp toward that angle with a "smoothing" variable.

Example:

transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(rotateHeading), Time.deltaTime * rotationSmoothing);
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 PrimeDerektive · Jan 10, 2011 at 01:47 AM 0
Share

I don't think that would work, because the character is always facing the mouse pointer (so you can aim your gun)... so in the event that you are moving and shooting, I can't be modifying his rotation both based on a movement heading and based on mouse position at the same time; and if I was shooting while moving sideways, a forward/backward run animation would look ridiculous.

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

No one has followed this question yet.

Related Questions

Simple NPC Character Movement with Mecanim 1 Answer

How to trigger animations in a script using character controller ? 0 Answers

Animated platform and twitching player 0 Answers

Top-Down Movement in Unity 1 Answer

How to move a character with animation on Android? 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