playMaker

Author Topic: Using Mecanim: Need some extra brain-power here.  (Read 4855 times)

Red

  • Hero Member
  • *****
  • Posts: 563
Using Mecanim: Need some extra brain-power here.
« on: May 05, 2013, 01:12:18 PM »
So, the control setup i have is much like the third-person framework asset pack and/or the tutorial system... it's using a simple object that only moves in horizontal and vertical relative to the camera (so, essentially i have values i can feed into mecanim to use to be able to trigger the appropriate animations.)

Thing is, the player mesh will rotate... and i'm having a hard time with the mental-stuffs to figure out what kind of algorithm i would need to use to be able to get it to move correctly...

So, say that i'm moving to the right (all movement is relative to the camera.) if it's facing forward, i can see the right movement triggering and the character would be side-stepping... but, what if the character is facing right as well? i'd want to have him walking right but so far i haven't been able to wrap my head around how to do this.

I'm going to guess that this is a mix between mecanim and playmaker so i'm not sure where to ask this (because if i ask this on the Unity forum, they likely won't be very easily able to answer this in regards to Playmaker's handling of it.)

does this help illustrate the mind-boggling i've been facing? I would gather that i could set up conditional statements for each quarter/eighth rotation... but i'm sure there's a much more contained, elegant way of implementing this.

so, to reiterate, the horizontal and vertical i can see working easily on it's own assuming the character never rotates and always faces in one direction... but, the mesh that's nested inside the main motion system rotates as needed. I know that it should be a simple thing to just extract the rotation and feed that to Mecanim, but i'm at a blank as to how to actually implement it.

Anyone?

Though i understand that this being a mecanim thing, it might be a mecanim issue... but, I was wondering if this is something i can just feed into the system or if i have to do a bunch of calculation on it first?

so, yeah... kinda in the dark here, would truly appreciate a torch :D
« Last Edit: May 05, 2013, 01:41:45 PM by Red »

Red

  • Hero Member
  • *****
  • Posts: 563
Re: Using Mecanim: Need some extra brain-power here.
« Reply #1 on: May 05, 2013, 03:40:57 PM »
Okay, i've been doing some research and brainstorming and a bit of trial-and-error... and i think i might have an idea, an inkling of how to approach this.

if i set up the system to handle a horizontal and a vertical (since i would not be able to simply pass the movement vector variable into mecanim) i can then tell it to just use that information... and a blending system can determine what's going on. so, there will be a state to trigger the animation to move forward, backward, laterally and diagonally between all four directions. this should cover the animation part of it.

Now comes the fun part which i'm not sure how to do... in theory, if i want to trigger it, i would have to extract the rotational data of the mesh object, compare it or calculate it against the root transform data (i'm not sure how this would work relative to the camera position... but on a static, not-relative-to system, it might help) and if i can somehow detect what direction the mesh is headed relative to it's rotation, then i can then (theoretically, haven't tried this yet, not sure how to set it up) figure out what the horizontal and vertical values would be and then feed those to mecanim. from there, mecanim can fire off the pertinent animations.

thing is, i'm not sure how to really calculate that. I mean, how does one calculate the relative motion of a vector based on it's local rotation?

example: Say the character is moving up... so, vertical with a value of 1. but they are facing to the right of the screen (so, a degree rotation of 90 or so)  how would i tell it (without hard-coding in all possible angles which would leave a nightmare of an FSM that'd probably be so clogged it'd bog down the system) to say that it's relative movement is essentially to it's left, therefore triggering the "sidestepping" animation segment in mecanim? is there a way to do something like that?

... if i can nail that, calculating the relative motion values of the vector based off of the local rotation of the mesh object, then the next step would be to confirm whether this would or would not work for a "relative to the camera" movement vector.

here are some numbers that might help further illustrate what i'm going for.

main root movement vector is 1,0 (so, up.)
character mesh is facing 90 degrees clockwise.
so, therefore, the relative movement vector should be 0,-1. (so, it thinks it's sidestepping to the left.

does that help?

here is another mental image that might help illustrate.

Character's root is moving to the right (so, movement vector value of 0,1)
Character's mesh is rotated 45 degrees clockwise from the direction it'd be facing*. (making the actual relative movement vector, according to mecanim, 1,1.)

*so, then it's local angle would be 135 degrees.

better?


... I'm willing to bet that there is an action that does this... or a set of actions... and it's staring me in the face but i just can't figure it out. not knowing what this kind of mathematical process is called is probably also not helping.
« Last Edit: May 05, 2013, 03:57:00 PM by Red »

escpodgames

  • Hero Member
  • *****
  • Posts: 687
    • Assets
Re: Using Mecanim: Need some extra brain-power here.
« Reply #2 on: May 05, 2013, 08:00:44 PM »
Hmmm I actually tried to set this up for my 48hr game comp entry.. but with no time it was submitted broken (opps) I never got anywhere with it just had thought about it. I have however setup a system in one of my other game for this.

So say you are moving forward (and facing forward) and the player moves right, this is a +90 angle change. If the player moved backward it would be +180 or -180 and a left movement would be -90. so what if the player is rotated 45 degrees to the left and moves right, the angle would be +135.

The key action you're waning to use here is GetSignedAngle.cs "GetEulerDeltaAngle" (might be a custom I found on this forum)
so basically you measure the move angle and add the rotational offset and then using a blend tree -180 to +180 you blend to the correct angle. (reset the direction to 0 after the blend)
« Last Edit: May 05, 2013, 08:07:34 PM by LampRabbit »

Red

  • Hero Member
  • *****
  • Posts: 563
Re: Using Mecanim: Need some extra brain-power here.
« Reply #3 on: May 05, 2013, 08:14:35 PM »
Thank you! though, it does look like that's a custom action. it's not showing up with this install (which afaik is up to date... but i could me wrong on that.)

though, with the resetting the angle to 0 at the end, is it safe to assume that this is on the Playmaker side of things? if so, i would guess that i'll have to set up the system to cycle through the actions?

so, Start>calculate>broadcast>reset>Start (et-cetera?)

escpodgames

  • Hero Member
  • *****
  • Posts: 687
    • Assets
Re: Using Mecanim: Need some extra brain-power here.
« Reply #4 on: May 05, 2013, 08:21:15 PM »
It would depend on the users input, I set something like this up for a camera/player direction system. Whilst the finger was down I would calculate the angle and update the rotation but once the finger was removed it would set the current direction as 0 as that is now forward.

Also attached the action :)

Red

  • Hero Member
  • *****
  • Posts: 563
Re: Using Mecanim: Need some extra brain-power here.
« Reply #5 on: May 06, 2013, 11:17:54 AM »
Allrighty, another day to tackle this.

So, then the way i would set this up would be to calculate the angle and then feed that angle data to Mecanim?

if so, any suggestions on how to set up Mecanim to handle this? It seems (without delving too deeply into it) that it's only really working with a rotation... so, i'm still unsure how to translate that into values such as horizontal and vertical values. I do want to see about keeping this as simple as i can since i'll have to set up at least 10 character classes for my game to be able to use this. (which i assume shouldn't be a problem per-se if i can get the algorithms set to work with them.

... heh, yeah... that's the downside of focusing on the art side of things... i'm definately an artsy person, math (well, anything more than BEDMAS) is not easy for my brain-meats to handle.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Using Mecanim: Need some extra brain-power here.
« Reply #6 on: May 07, 2013, 03:38:00 AM »
Hi,

 yes, that's how the robot example works, you compute the angle and then tell mecanim what angle it is, and you can then map animations based on the angle, pretty powerful actually. Check out the "Generic Skeleton Example" scene.

bye,

 Jean