playMaker

Author Topic: Keeping player in screen [SOLVED]  (Read 8008 times)

perdido007

  • Playmaker Newbie
  • *
  • Posts: 24
Keeping player in screen [SOLVED]
« on: January 12, 2014, 02:32:53 AM »
Question from newbie city…how would i keep my player from going of screen: 2d sidescroller with tk2Camera and thinkscroller as my assets all working fine, but my player sometimes goes off screen, i would like to avoid that, how would i do that ? Help appreciated, cheers :)
« Last Edit: January 19, 2014, 05:06:30 AM by perdido007 »

phannDOTde

  • Full Member
  • ***
  • Posts: 237
    • Peter Hann .de
Re: Keeping player in screen
« Reply #1 on: January 12, 2014, 08:28:18 AM »
I do it with an every frame loop
 - get position
 - clamp Values (Y,X min/max Positions)
 - set position

inside my steering State witch is running all the time anyway

greets
Peter

if you wanna see my result in action: http://www.peter-hann.de/projekte/cyberpunk-3776/

perdido007

  • Playmaker Newbie
  • *
  • Posts: 24
Re: Keeping player in screen
« Reply #2 on: January 12, 2014, 10:42:07 PM »
Thank you Peter, will give this a try and keep you posted. Cheers

perdido007

  • Playmaker Newbie
  • *
  • Posts: 24
Re: Keeping player in screen
« Reply #3 on: January 13, 2014, 11:53:24 PM »
no definitely cannot get it to work….tried a couple of things from forum but i cannot make heads of it…any help appreciated….cheers…posting here one of the ways i have tried but to no avail...

phannDOTde

  • Full Member
  • ***
  • Posts: 237
    • Peter Hann .de
Re: Keeping player in screen
« Reply #4 on: January 14, 2014, 02:14:32 AM »
More like this Screenshot - just seperate it from your steering or do it inside your steering loop at every frame end

perdido007

  • Playmaker Newbie
  • *
  • Posts: 24
Re: Keeping player in screen
« Reply #5 on: January 15, 2014, 02:32:44 PM »
Thank you Phann DOT DE but i am not getting the result my player just bumbles stuck on the same spot, i am sure that i am doing something very wrong, am trying to find a workaround this by moving player along the x axis and not alloying him to move along the y axis, by putting a cube on top of him to act like a sky slightly off screen so that he hits it on the way off screen but it kinda seems as if i'm putting scotch tape over an open cut….strange but we learn, we learn…..thanks

phannDOTde

  • Full Member
  • ***
  • Posts: 237
    • Peter Hann .de
Re: Keeping player in screen
« Reply #6 on: January 16, 2014, 12:47:40 AM »
Hey,

using Collider boxes as screenboundarys can have unwanted sideeffect later in development - I did the same at first approach. Ended up with a lot of them as boundarys, bulletcatchers end stuff ;-)

How ever I made a really simple sample scene for you. Might work better if you got higher Worldsize than the defaults and somehow Translate "per second" dont wanna work (not sure why) but this may be help you anyway to start with.

perdido007

  • Playmaker Newbie
  • *
  • Posts: 24
Re: Keeping player in screen
« Reply #7 on: January 16, 2014, 02:15:51 AM »
Hey, first of all thank you for coming back, yes indeed you are right playing with off screen cubes as limits is proving also not to be so simple, have now got this scene going in simulator but on iPad it all goes wrong i.e. my player goes through the roof i.e. sky in this case, thank you for your build…but i can't open it…i'm looking for Tester_Steering in my project but cannot find it…could it be because the word package is missing at the end…?

perdido007

  • Playmaker Newbie
  • *
  • Posts: 24
Re: Keeping player in screen
« Reply #8 on: January 16, 2014, 02:29:14 AM »
no…ignore…just dumped it into unity and opened scene…am now looking into it and will keep you posted…cheers and thanks again…

phannDOTde

  • Full Member
  • ***
  • Posts: 237
    • Peter Hann .de
Re: Keeping player in screen
« Reply #9 on: January 16, 2014, 02:58:17 AM »
couldnt send you a package because I'm using a Playmaker Beta and it would include beta sources. Dont got any experience with Ipad restrictions - just developing for PC so far. When you enable "per second" at the Translate Action you might need to adjust the Multiplier on "Get Axis" for higher speeds.

All so you might need to adjust the Clamp Values to fit your Project

perdido007

  • Playmaker Newbie
  • *
  • Posts: 24
Re: Keeping player in screen
« Reply #10 on: January 17, 2014, 10:02:17 AM »
Ok so now have spent quite some time with this and i cannot get this thing to work…my player now just hang in mid air trembling…he has lost his gravity…tried tweaking the steering example but to no avail, tried a little via a limit right/limit left FSM from those C# games where there is an example of a limit but i can't get this thing to work…how does every body else do it…i am sure i am doing something not right but where? help appreciated….
« Last Edit: January 17, 2014, 10:04:42 AM by perdido007 »

redikann

  • Full Member
  • ***
  • Posts: 174
Re: Keeping player in screen
« Reply #11 on: January 17, 2014, 10:53:05 AM »
This probably won't be the best solution but maybe you can try this until someone gives you something better. When you start your game design so the player begins at 0,0,0. Now just get position every frame and store it in a variable ( probably break the vector into its x,y,z components). Now just setup some logic that at a hard coded distance from origin you can force the player to stop and or turn around and travel in the opposite axis.
This doesn't give you flexibility for multiple resolution but you can always play around with screen to world space actions.
« Last Edit: January 17, 2014, 10:55:20 AM by redikann »

phannDOTde

  • Full Member
  • ***
  • Posts: 237
    • Peter Hann .de
Re: Keeping player in screen
« Reply #12 on: January 18, 2014, 07:44:34 AM »
Not sure what more can I advice you since I cant see want you might doing wrong.

perdido007

  • Playmaker Newbie
  • *
  • Posts: 24
Re: Keeping player in screen [SOLVED]
« Reply #13 on: January 19, 2014, 05:05:48 AM »
Thank you PhannDOT de for your help and redikann. Finally found a workaround which involves colliders placed on the skybox which acts as a limit to the upper movement of my player, as soon as player gets to close to upper limit he is triggered to reborn a little lower on the screen and it works perfectly on iPad 1.Am posting a screenshot of FSM. Cheers and thanking you once again...

Peeter1978

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Keeping player in screen [SOLVED]
« Reply #14 on: April 26, 2021, 05:04:00 AM »
Hi,
Just stumbled onto this 7 year old thread as I am having the exact same problem - I have a sidescroller with an the enemy spawner which moves along Y axis in a pingpong movement up and down, but every time either the player gets killed or a new level is started, the spawner gets out of place - the game killes off the spawner along the enemy as it should, but respawns the spawner in a random location along the Y axis and as I have set my spawner to move 30 units up and down, it starts this movement routine at the spawn position, causing it to move outside the play field. And whatever I do, I cannot do anything to make it stay in the bounds of the game. Some kind of Get Position-Set Position is obviously needed but as I followed the instructions given in this thread, all I managed was to get spawner just get stuck and not move or spawn enemies at all. :(