Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Thomas-Hawk · Apr 09, 2018 at 12:30 AM · rotationtransformscalehandsheirarchy

I'm interpolating an object between positions and rotations. Now I need to make sure it happens in front of the camera.

So, I have a melee attack script, which interpolates the weapon between positions and rotations to create the melee attack motion.

  • I have the weapon as a child of "Hands" which is an object positioned sensibly for things being held.

  • "Hands" is parented to my player, so it stays in front of the player

  • I want the hands to stay in front of the torso, but I can't parent them to it, so I have an object parented to the torso, and I'm scripting the "Hands" position and rotation to match that.

  • I'm using animator hints to make the torso and head look up and down with the camera

  • But when I run my interpolation function, to "swing" the object based on predetermined positions, those positions are happening in local player space, as opposed to, well, local "torso" space

Now I basically want the behavior of, those local positions being applied as if they were local positions of the torso object, as opposed to the player (which it must be parented to.)

I was thinking things like "torsoObject.position + the melee interpolation step position" but while it was consistently affecting it, it wasn't doing what I needed it to, just for example of what I'm trying to do.

Here is a video to show the problem: https://youtu.be/E0lXQR518kk

Note that I am successfully keeping the weapon within view of the camera, until I attack. Then, it is using positions which were defined as local positions, as a child of the player object. I need those positions to change as if they were defined as local to the torso object (the one it copies the transform of until we attack).

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
Best Answer

Answer by Eno-Khaon · Apr 09, 2018 at 12:51 AM

As long as you know your "target" positions relative to the torso (which you mention having a series of them to interpolate between, you should be able to use Transform.TransformPoint(Vector3) to translate from the torso-based position to the world-space position suited to it.

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 Thomas-Hawk · Apr 09, 2018 at 01:15 AM 0
Share

I am sure this is my answer, but I really need help wrapping my head around it.

Here is the hierarchy:

  • Player

  • ^}Hands Object (Has a script to copy "Hands Position" transform, only while not attacking)

  • ^}Skeleton

  • ^^}Torso

  • ^^^}}Hands Position

The positions I have an array of, were made local to the player, without considering I would want to perform these "swings" relative to the torso.

Since they are localpositions, I set the localPosition of the hands object to move it, lerping from position to position, resulting in the position being relative to the player, since of course it is a child of the player.

I need it to be as if they are relative to the "Hands Position". I can't simply parent it because of issues with scale and logic.

So, where do I call this Transform.TransformPoint? Do I run that before interpolating the hands, giving it the torso objects vector? Or what is the order of operations here?

I'm doing "hands.localPosition= Vector3.Lerp(posA, posB, t)";

where posA and posB are both local positions, relative to the player object, that I need to be relative to the torso object.

Please give an example of how to use this!

avatar image Thomas-Hawk · Apr 09, 2018 at 03:52 AM 0
Share

I made it work! This is specific to my use but sharing how I did it.

     int i = 0;
             if(calc){
     
             foreach (Things.$$anonymous$$eleeAttack atk in dirs) {
                     int b = 0;
                     foreach (Things.moveStep step in atk.steps){
 //Take the vector the hands would be at locally to the player, turn that vector into a world point.
                         atk.steps [b].pos = randyHands.TransformPoint (step.pos);
 //Take that world point, convert it into where the hands should be relative to the torso object.
                         atk.steps [b].pos = movesWithTorso.InverseTransformPoint (atk.steps [b].pos);
                         b++;
                     }
     
                 i++;
             }
     
         }
 

Then I just copied the list during run-time and pasted the component values into the script those vectors are stored in. Worked like a charm.

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

121 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

Related Questions

Problems with scale and rotation 2 Answers

Locking transform, rotation, scale, etc in the inspector window 1 Answer

How do I replace an old gameObject with a new one while keeping the functionality of the old one?,How do I replace my current gameObject with a new one while maintaining the functionality of the old one? 2 Answers

[solved] Get upward orientation of object and add scale value 1 Answer

postion scale and rotation greyed out and not working 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