playMaker

Author Topic: 2D Character Orientation based on Platform Angle [SOLVED]  (Read 5269 times)

davidwaters01

  • Playmaker Newbie
  • *
  • Posts: 5
2D Character Orientation based on Platform Angle [SOLVED]
« on: May 08, 2014, 07:42:32 AM »
Hi

Newbie to coding and Playmaker here and need a push in the right direction please.

I am creating a 2D game where a character jumps from platform to platform (mechanic is similar to Kingdom Prince - image attached ).

I have setup the collisions and jumping and have the character (Rigidbody) parenting / unparenting and revolving around the platforms.

However what I am struggling with is getting the character to orientate itself on a new platform following a jump.. For example the character starts upright  (feet on the platform) however if I jump the character to a new platform it is orientated at the angle that it collided with the platform (for instance if the second platform was directly above then the characters head would be on the platform).

What the script is doing is when a collision is detected between a platform and the character it parents the character to the platform it collided with and sets the characters isKinematic to true.

Please can someone suggest how I can change the characters orientation after jump so that it will always land on its feet.

Thanks for any help or suggestions

« Last Edit: May 11, 2014, 11:42:57 AM by davidwaters01 »

davidwaters01

  • Playmaker Newbie
  • *
  • Posts: 5
Re: 2D Character Orientation based on Platform Angle
« Reply #1 on: May 09, 2014, 10:24:16 AM »
Allrighty so I just had a bit of a light-bulb moment (which i hope doesn't pop and fizzle  :) )

I am going to try and use the collision get info module and use the collision normal and rotate the object to orientate along the characters Y axis.. somehow.

I will play around with this tonight and if i can get it to work Ill post the solution, however if you have any suggestions or a better way please let me know.

TrentSterling

  • Junior Playmaker
  • **
  • Posts: 89
  • Someday I'll make games!
    • My Blog
Re: 2D Character Orientation based on Platform Angle
« Reply #2 on: May 09, 2014, 10:26:41 PM »
Assuming the platforms are all circles, you might use the LookAt action to orient the sprite- making it always 'look at' the center of the object.

Otherwise, you'd probably want to go ahead and get the collision normal. Then you can use LookAtDirection action. You'll probably have to screw around with pivots to make it all work right.  :-\

TrentSterling

  • Junior Playmaker
  • **
  • Posts: 89
  • Someday I'll make games!
    • My Blog
Re: 2D Character Orientation based on Platform Angle
« Reply #3 on: May 10, 2014, 08:37:10 PM »
I went ahead and did a prototype based on the collision normal. Turns out to be a pretty fun little prototype.



I'll edit this post with the actions once I clean them up. It's really just listening for collision, getting the normal, LookAt the normal, set parent, set kinematic, and wait for input.

On input, unparent, set non-kinematic, and add some force. You're already pointed away because you aligned to the normal. Works quite well.

EDIT: Album link with all the action stuff here: http://imgur.com/a/5EY8w
« Last Edit: May 11, 2014, 12:37:40 AM by TrentSterling »

davidwaters01

  • Playmaker Newbie
  • *
  • Posts: 5
Re: 2D Character Orientation based on Platform Angle
« Reply #4 on: May 11, 2014, 08:51:24 AM »
THANKYOU...
I am struggling to get this working but your example is EXACTLY What I am trying to do..

Please please can you send me the scene file so that I can see how everything fits together. I'll PM you my email address.

davidwaters01

  • Playmaker Newbie
  • *
  • Posts: 5
Re: 2D Character Orientation based on Platform Angle
« Reply #5 on: May 11, 2014, 11:41:58 AM »
You sir are a Frikken LEGEND.. thank you so much for your help on this.

If you are ever in the UK / London then I owe you a beer.

Thanks again.

TrentSterling

  • Junior Playmaker
  • **
  • Posts: 89
  • Someday I'll make games!
    • My Blog
Re: 2D Character Orientation based on Platform Angle [SOLVED]
« Reply #6 on: May 11, 2014, 04:21:13 PM »
I'll upload a package tonight. I've never made a package that excludes a project like playmaker, so I hope it's smart about dependencies. :-\

TrentSterling

  • Junior Playmaker
  • **
  • Posts: 89
  • Someday I'll make games!
    • My Blog
Re: 2D Character Orientation based on Platform Angle [SOLVED]
« Reply #7 on: May 11, 2014, 08:39:32 PM »
Ok, I made this in a hurry, so instead of XY plane, I made the game play on the XZ (mostly so I don't have to specify an Up axis for the LookAt action)

Knowing this, you'll have to make gravity act on the Z axis instead of the Y. Here's what it should look like:



EDIT: I forgot to mention a disabled FSM. You can enable it to align the character to his velocity. So he will rotate according to his movement arc. It's not exactly finished. You might stick with just the snapping movement.





You can find the package here:
https://dl.dropboxusercontent.com/u/185467974/planetpackagetest.unitypackage


EDIT: I attached it via the forums as my dropbox gets shuffled a lot.
« Last Edit: May 16, 2014, 09:10:26 PM by TrentSterling »

davidwaters01

  • Playmaker Newbie
  • *
  • Posts: 5
Re: 2D Character Orientation based on Platform Angle [SOLVED]
« Reply #8 on: May 12, 2014, 01:33:05 AM »
Thanks Trent

Will download and have a play..

I am currently taking your structure and transposing it into the 2d nodes.

thanks again for all your help on this.