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 FGPArthurVII · Mar 22, 2015 at 08:46 PM · c#jointboneskeleton

How to move/rotate joints using c#?

Right, I have an character for a FPS game (in this case I'll have to use the entire body instead of the cutten arm), let's suppose I have an aiming walk animation, but as almost all FPS it deals with mouselook, for improvement and realism, things such as arms, waist, and head has to rotate so the character can look to the direction I'm looking. But how can I do it on csharp? what are the lines and commands, and how am I going to do it without conflicts with the animation? and what is the process on the own engine?

Thanks for all the ones who help me...

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
1

Answer by Cherno · Mar 22, 2015 at 08:52 PM

Supposed you want your upper body to rotate around the x axis (up & down) so that it faces the point the camera is looking at. First, you need a Vector3 variable which holds the point in world space that the upper body should be rotated towards. Do a raycast from the camera forward and use the hit.point as the lookat position. If the ray hits nothing (yu might be aiming into the sky), just use a spot which is in the camera's forward direction, times 100 units or so (doesn't really matter).

Now for the actual rotation. Let's assume you upper body starts with a spine bone which has the pelvis bone as it's parent and it's child is another spine bone further going into the torso. This spine bone is the bone we will rotate. All you need to do now is add a line in the LateUpdate() function (so the rotation is applied after the rotations fro any animations playing):

 privateVector3 aimingTargetPos;
 private Transform torsoPivotBone;
 
 void LateUpdate() {
      torsoPivotBone.LookAt(aimingTargetPos);
 }

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

How do I drag a bone from a 3D model onto my custom component? 1 Answer

Distribute terrain in zones 3 Answers

combine Spring + Hinge in one ConfigurableJoint 0 Answers

How to make a Texture2D be constructed as a Clear texture 3 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