playMaker

Author Topic: Help Needed: Physics Based Platformer  (Read 2230 times)

JD

  • Playmaker Newbie
  • *
  • Posts: 5
Help Needed: Physics Based Platformer
« on: August 31, 2015, 07:31:20 PM »
Hello,

Thanks in advance for taking the time to read my question!  I'm trying to create a physics based platformer and I've run into a bit of a problem with character control.  My apologies, I'm very new to Unity and Playmaker so please bare with me.  The character control scheme that I've envisioned is as follows:

  • Left mouse click: charge jump
  • Release left mouse: Jump
  • Arrow Keys: moves character on the x and z axis (character can only move on the x and z in the air/mid jump)

I'm using an "add force" on the Y axis for the jumping action which activates upon left mouse button release.  I need some way to move the character around in the air (x and z axis) only if the jump has been initiated. 

I've tried to use "Get Axis Vector" and "Controller Simple Move" but this doesn't work.  In this situation the character gets grounded as soon as jump is released.

I've also tried using an "Axis Event" along with "Add Force" upon mouse button release.  This gives me something in the ballpark of what I'm intending but it doesn't give me the precision that I'm looking for. 

I want to be able to hold the arrow for a sustained move or tap it for a precision move.  I'd like to be able to terminate my left input with a right input.  Basically I'm looking for standard 3rd person controls when (and only when) my character is in the air.

Any suggestions are greatly appreciated.  Many many thanks!
« Last Edit: September 02, 2015, 12:21:23 PM by JD »

Grendal

  • Playmaker Newbie
  • *
  • Posts: 31
Re: Help Needed: Physics Based Platformer
« Reply #1 on: August 31, 2015, 09:50:04 PM »
I am assuming you have a controller component on your player.. use the action "Controller is Grounded"
Quote
Tests if a Character Controller on a Game Object was touching the ground during the last move.

Game Object -The GameObject to check.
True Event - Event to send if touching the ground.
False Event - Event to send if not touching the ground.
Store Result - Store the result in a bool variable.
Every Frame - Repeat every frame.

JD

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Help Needed: Physics Based Platformer
« Reply #2 on: August 31, 2015, 10:28:25 PM »
@Grendal

Thanks for the response!  So if my "Controller is Grounded" = false then should I transition to a state with "Get Axis Vector" and "Controller Simple Move?"  My main problem is finding a way to allow 3rd person style control while my character is airborne.

I was able to do this roughly with "Get Mouse Up" then transition to "Axis Event" and then transition to "Add Force" (one Add Force for each direction along X and Z).  My problem is that it didn't allow for fine control - one button push in any direction sent my character flying away without the ability to modulate or add opposite force to the motion.

Thanks again for your response!  I'll look into "Controller is Grounded."  Please let me know if the above notes clarify my problem or bring any other solutions to mind.  :)

Grendal

  • Playmaker Newbie
  • *
  • Posts: 31
Re: Help Needed: Physics Based Platformer
« Reply #3 on: August 31, 2015, 11:16:05 PM »
Have you thought about "simulating" the affect your after?

Put an invisible cube with controller component on it and make your player a child of it. Now when the player "jumps" translate the player mesh only and not controller cube he is always in control but just "looks" like he is in the air... you could set a inAir variable to turn off jump etc. and translate back using a tween or animate variable when "landing"...or just turn off collision on controller cube till player falls back down then restore controller cube to player tranform... I spent a lot of time in Construct2, I am all about simulating stuff.


This is for a rocket pack style look... sound like your more after a Super Mario look?
« Last Edit: August 31, 2015, 11:23:22 PM by Grendal »

JD

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Help Needed: Physics Based Platformer
« Reply #4 on: August 31, 2015, 11:59:35 PM »
@ Grendal

That's a very clever idea!  Thank you!  I will experiment with this approach and report back.  :)

JD

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Help Needed: Physics Based Platformer
« Reply #5 on: September 02, 2015, 12:20:19 PM »
@ Grendal

I used the invisible cube method that you suggested as well as a few other tricks to get it working.  I also used an "enable/disable FSM" to terminate the ability to move once grounded.  Thanks so much for the advice! :)