• 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 saad321315475 · Aug 28, 2020 at 07:31 PM · rotationairagdoll

Ragdoll AI rotation towards target?

I'm trying to make an AI, so it detects when the player is within range, to face towards him. Below is the script that I'm using, but when the ragdoll reaches > 90 && < 270 (At the back of the transform and sides), it doesn't rotate to those angles, only 0 - 90 && 270 - 360 (At the front and sides) . I tried to Quaternion. Inverse it, but no luck.

Does anyone have a solution?

void EnemyRotation() { lookingAtPlayer = enemy.GetPlayerSeen();

     if (!lookingAtPlayer)
     {
         // Atached to the root from a different script
        //public Vector3 GetDirection()
        //{
           // return (player.position - transform.position).normalized;
          //}

         var lookPos = enemy.GetDirection();
         var rotation = Quaternion.LookRotation(lookPos);

         APR_Parts[0].GetComponent<ConfigurableJoint>().targetRotation =
                 Quaternion.Slerp(APR_Parts[0].GetComponent<ConfigurableJoint>().targetRotation,
                 new Quaternion(rotation.x, rotation.y, rotation.z, rotation.w), Time.deltaTime * turnSpeed);

         Debug.Log("Looking for the player!");
     }
     else
         Debug.Log("Found player!");
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
0

Answer by N-8-D-e-v · Aug 28, 2020 at 08:11 PM

I'm making a game with 2d ragdolls right now, so I can actually kind of help you from the top of my head. Maybe just try rotating the body like so

 bodyRigbody.MoveRotation(Quaternion.Slerp(targetRot, speed * Time.deltaTime);

Not sure if this will work, but if it doesn't let me know and I will try to help

Comment
Add comment · Show 4 · 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 saad321315475 · Aug 28, 2020 at 09:45 PM 0
Share

Tried it, didn't work, unfortunately, it starts to do weird rotations

APR_Parts[0].GetComponent().$$anonymous$$oveRotation(Quaternion.Slerp(APR_Parts[0].GetComponent().targetRotation, new Quaternion(rotation.x, rotation.y, rotation.z, rotation.w), Time.deltaTime * turnSpeed));

avatar image N-8-D-e-v saad321315475 · Aug 29, 2020 at 04:51 PM 0
Share

the first argument in Quaternion.Slerp is the starting rotation, so flip those two around. Also, make sure target rotation is a quaternion

avatar image saad321315475 N-8-D-e-v · Aug 29, 2020 at 06:08 PM 0
Share

So i tried this and this happens:

var lookPos = enemy.GetDirection();

var rotation = Quaternion.LookRotation(lookPos);

APR_Parts[0].GetComponent().$$anonymous$$oveRotation( Quaternion.Slerp(new Quaternion(rotation.x, rotation.y, rotation.z, rotation.w), APR_Parts[0].GetComponent().targetRotation, Time.deltaTime * turnSpeed));

https://gyazo.com/844a3cebe15a5e50724e74820187f7d6

Show more comments
avatar image
0

Answer by saad321315475 · Aug 28, 2020 at 11:40 PM

APR_Parts[0] is the root bone in the ragdoll just to clarify

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

253 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 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 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 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 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 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

Ragdoll Base 2 Questions 0 Answers

How to make ragdoll arms point towards mouse? 1 Answer

Rotating enemy object to face the player when moving 2 Answers

How to prevent arcing rotation? 3 Answers

Lock rotation of object 4 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