playMaker

Author Topic: [SOLVED] Get Animated Bone World Space Position?  (Read 3135 times)

Kathar

  • Playmaker Newbie
  • *
  • Posts: 48
[SOLVED] Get Animated Bone World Space Position?
« on: May 16, 2018, 02:59:30 PM »
Me again! (sorry!) Done a lot of searching but couldn't find anything for this - basically I've got an animated character, and I want to grab the World Space Position of the hand bone, so I can do certain things with it, like have a laser sight start from the end of the hand/gun, and create 'Pow' sound effects at this point etc. Parenting things to the bone won't really work for what I need to do with it, so I really need to grab the world space position of it. Is it possible to do this? The transform of the Game Object in the Unity Editor seems to be of no help, and no luck using Get Position either. I think I need something bone-specific, but couldn't find any actions for this.

Thanks for any insight/help!
« Last Edit: October 06, 2018, 06:43:03 AM by Kathar »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Animated Bone World Space Position?
« Reply #1 on: May 22, 2018, 05:11:33 AM »
Hi,

 uhm, I'll try to have a look, please bump me end of the week if I haven't replied.

 Bye,

 Jean

Kathar

  • Playmaker Newbie
  • *
  • Posts: 48
Re: Get Animated Bone World Space Position?
« Reply #2 on: May 22, 2018, 08:19:13 AM »
Thanks Jean - I did manage to find this thread which may do what I need: https://answers.unity.com/questions/1093623/following-bone-position-during-animation.html

It mentions subtracting the character's global position from the bone's global position to get the bone's position. I haven't had chance to try this just yet, but I'll let you know if it does/doesn't work :)
« Last Edit: May 22, 2018, 02:34:22 PM by Kathar »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Animated Bone World Space Position?
« Reply #3 on: May 23, 2018, 01:57:39 AM »
Hi,

 ok cool :)

 Bye,

 Jean

Kathar

  • Playmaker Newbie
  • *
  • Posts: 48
Re: Get Animated Bone World Space Position?
« Reply #4 on: May 27, 2018, 06:17:03 AM »
So I've tried the above solution, but I'm not having any luck with it so far. My game is 2D-oriented, and so setup in the X/Y planes, but when I try and Get the World Position of the Bone, it returns some extreme values, like -100'ish in the Z-axis, which really doesn't feel right at all. Realistically the Z value should return with a value between 0 to -1, at most... but that's not the case. So no matter how I subtract the Position vectors etc, it's always coming out with a weird value. The Pelvis bone is the highest part of my hierarchy that also has an extreme value like of -100ish, so I did try subtracting the vector from that (and vice versa), but still no luck, however I add/subtract them, I still don't get a value that's close.

Massive bodge, but I had toyed with the idea of parenting/deparenting an Empty GameObject every frame from the Hand Bone, just to grab the position from that GameObject when it's unparented, but I can't seem to get it to unparent at runtime without affecting its position. If I drag the Hand Bone etc. out of the Hierarchy just in the editor it works fine, like the hand doesn't move and I can grab the Position perfectly, but no luck doing that in-game yet. And does feel a bit dirty doing it that way anyway, so maybe that isn't the solution.

I've tried searching for this a lot on google, because I feel it's obviously more a Unity issue than Playmaker itself, but really haven't had any luck. So if you did have any ideas Jean that would be amazing :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Animated Bone World Space Position?
« Reply #5 on: May 30, 2018, 03:05:12 AM »
Hi,

 can you provide me with a scene and  a setup and tell me which object you want to get the world position from and I'll work on it, I think you have an very specific setup which might be the issue.

 Bye,

 Jean

Kathar

  • Playmaker Newbie
  • *
  • Posts: 48
Re: Get Animated Bone World Space Position?
« Reply #6 on: October 06, 2018, 06:42:46 AM »
Hi,

 can you provide me with a scene and  a setup and tell me which object you want to get the world position from and I'll work on it, I think you have an very specific setup which might be the issue.

 Bye,

 Jean

Sorry Jean, massive bump, but never realised you'd replied to this! Appreciate your offer to help! Just to follow up in case anyone else has this issue- I did get this sorted in the end. You're right, it was an error on my part. Basically I had a ragdoll system in place, so when a character gets stunned they'd ragdoll, and then unragdoll after a few seconds. Turns out I was never disabling the gravity/colliders on the individual limbs, so Unity was calculating the physics of the limbs (hence the massive transform values of the hands, like -200 in z), but then the Animator was visually overriding it, so I wasn't aware it was doing this behind the scenes. As soon as I correctly started disabling colliders, and enabling Is Kinematic, and disabling Use Gravity on the rigidbodies when the Animator was enabled, it all works perfectly :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: [SOLVED] Get Animated Bone World Space Position?
« Reply #7 on: October 08, 2018, 03:26:29 AM »
Hi,

 thanks for getting back and documenting your setup.

 Bye,

 Jean