playMaker

Author Topic: [SOLVED] Storing player position, and other questions  (Read 2841 times)

stansdad

  • Playmaker Newbie
  • *
  • Posts: 18
[SOLVED] Storing player position, and other questions
« on: September 30, 2012, 12:37:02 PM »
Hi there

I bought Playmaker around a month ago and am slowly progressing with a mock up of a game I'm making.

I have a few questions.  Here is what I am trying to achieve:-

1)  I have a character who is able to fall off a platform in a 3d isometric game.  I have a trigger plane underneath it, and have an FSM in place which checks for the trigger (on trigger enter) and then sends an event. Eventually I'll add this to a health variable as per the tutorials.

In the event, what I would like to happen is that the character respawns in about the same position that he fell off at.  So I need some way to store the characters Vector 3 constantly as a "last grounded position", then respawn at that point.

I believe I cannot use IsGrounded as I am using a physics based character, not the character controller.  if I can use IsGrounded, then I'd need someone to help me out with that.

2)  Related to this, I have a kind of "emergency stop" function when pressing space.  At present I am botching it by using "Rigidbody - sleep".  But this has the unwanted side-effect of stopping the character mid-air or wherever he is.  I need this to only be able to function when he is grounded.

Has anybody got any suggestions on that?

Many thanks in advance for any help.  I'm muddling through!
« Last Edit: October 01, 2012, 05:25:16 PM by stansdad »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Storing player position, and other questions
« Reply #1 on: October 01, 2012, 01:16:18 AM »
Hi,

 simply check for collision detection with the ground.

tag all your ground meshes with a new tag "ground", and have an fsm checking collision with any "ground" layered meshes. you'll then be able to know when your player is grounded or not.

Use the action "Collision Event" and select "ground" in your "collide tag" property.

Does that make sense?

bye,

 Jean

stansdad

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Storing player position, and other questions
« Reply #2 on: October 01, 2012, 04:35:06 PM »
Hi Jean

Thanks for the reply.  It makes sense and I think I have sorted the "is grounded" but now having trouble setting the position back to the platform after falling.

I've set up a FSM called "Store Grounded Position" on the Player using Collision Event, set to "On Collision Enter", Collide tag "grounded", send event "Store Vector 3"

Then in the second state I've used "Get Position" with a Global Vector called "Last Player Position", in World Space, every Frame.  Then send that back to the start state with "finished'.  That seems to be working because every time he hits a new patch of ground, it seems to update in the Gizmo.

So far so good

However, on my "lose life" collider plane under the main platforms, I'm trying to use "Set Position", referencing Player, using the global variable "Last Player Position", in World space, just once, not every frame.

But nothing happens, he just keeps falling.

I know the triggers are working as I am seeing that in runtime.

Do I need to use something other than Get/Set position?  I feel like I am close, but not quite there!

stansdad

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Storing player position, and other questions
« Reply #3 on: October 01, 2012, 04:45:12 PM »
Here's my player FSM

I think I know what's wrong, I probably need a Bool in here somewhere to have an event that updates the LastPlayerPosition global variable if grounded, but doesn't update it if it's not grounded.

That might take the best part of a week to learn so if anyone has an easy solution I am all ears  :)

stansdad

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Storing player position, and other questions
« Reply #4 on: October 01, 2012, 05:16:12 PM »
Ahh, I've solved it!

Here is my new Player FSM attached, also my new LoseLifeCollidePLane which is under the ground.


The player has a "on collision Enter" which continually stores the Vector 3, then Next Frame event back to the idle state

It has an "on collision exit" which simply sends to "is not grounded" which only contains a next frame event back to the idle



Then, in the collider plane, it looks for all objects tagged "player" (there is of course only 1) and then the position is set.  There is a next frame event back to idle so that it can be reused.


All that is left is working out how to stop the player momentum when it returns to the platform, which I imagine will be a simple "rigidbody - sleep" function, or similar.

i hope this helps people