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 MP0732 · Nov 21, 2012 at 05:04 PM · animationrotationcollider

Enemy AI capsule collider tilts when moving

I have set the collider's rotation along all axes to zero. I have constrained the collider's position and rotation along its XYZ axes. I have added mass to its rigidbody. I have checked the the rotation of the game object during animation in Blender (it was upright).

Yet, whenever I hit play, the collider rotates back along the X axis, making the AI appear to be leaning back about 10 degrees. Regardless of the direction he is moving, he looks like he is going to fall backwards.

Any suggestions?

Update: I tried adding this to the Update function.

 gameObject.transform.rotation.x = 0;

It had no effect.

Comment
Add comment · Show 7
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 sparkzbarca · Nov 21, 2012 at 05:10 PM 0
Share

collider is a child of the player. Player is probably leaning back through code or animation.

cast a debug ray from player position to player transform up

is the ray angled or straight up on a flat surface?

avatar image MP0732 · Nov 21, 2012 at 05:37 PM 0
Share

O$$anonymous$$, the ray drawn in the first frame is straight up. Every subsequent ray is angled back, apparently at the same angle as the collider.

The surface isn't completely flat--it's a terrain--but the difference between the first frame and every subsequent frame is abrupt and significant. I guess that indicates something in the code or animation is the problem, right?

avatar image sparkzbarca · Nov 21, 2012 at 05:51 PM 0
Share

yep as i suspected your player is somehow having what it thinks is up modified. I.E your player is being rotated somehow.

what this tells you is the problem isn't in the collider its in the player.

disable and enable the animation script to see if its animation problems.

avatar image MP0732 · Nov 21, 2012 at 06:00 PM 0
Share

O$$anonymous$$, well I disabled the animation script during runtime, but the collider kept its (incorrect) rotation.

avatar image sparkzbarca · Nov 21, 2012 at 06:10 PM 0
Share

well its not animation something is rotating the object. $$anonymous$$aybe use debugging to monitor the Y axis rotation and when it changes

Show more comments

1 Reply

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

Answer by MP0732 · Nov 24, 2012 at 05:48 AM

OK, I finally figured out what the problem was.

I had set the enemy AI's target position along the Z, X and Y axes. This caused the enemy AI to "tilt" up or down along its own Y axis in order to reach the target.

To fix the tilting, I just zeroed out the Y axis value of the target position. I found the following code on the answer to another question, elsewhere on the forum.

Hat tip, and many, many thanks, to Aldo Netto.

 function Update () {
     var lookDir = target.position - myTransform.position;
     lookDir.y = 0; // zero the height difference
     myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
     Quaternion.LookRotation(lookDir), rotationSpeed*Time.deltaTime);
     myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
 }


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

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

11 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

Related Questions

Animation affects the rotation.. 1 Answer

Lerping smoothly between animation and new position 2 Answers

Animation problem with rotation and position. 0 Answers

Rotation Y axis is bugged. 2 Answers

Type of 3D Rotation Animation used in this video 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