How do I move a sprite half way across the screen only?

Get help using Construct 2

Post » Sun Mar 06, 2016 12:12 am

I'm trying to make a 2 player Pong type game but rather than having just up/down direcions..I have 4 directions.....my problem is trying to find a way to control the distance of the left/right movement. I don't want my players to move any than the center of the screen whether the player is on the left or the right side of screen.
B
10
S
2
G
1
Posts: 23
Reputation: 693

Post » Sun Mar 06, 2016 1:42 am

if player1 X coordinates > than window width/2 then set player1 X to window width/2
same goes for player2 if X coordinates < window width/2 then set player2 x window width/2
B
9
S
3
Posts: 58
Reputation: 805

Post » Sun Mar 06, 2016 1:43 am

Hope this helps .. Easiest way i came up with .... Im sure there is a more precise way to do it but that just came off the top of my head and was real simple :)
B
9
S
3
Posts: 58
Reputation: 805

Post » Sun Mar 06, 2016 1:49 am

Oh, was too late - same idea, but I also have a second solutions so I post it anyway

I'm not sure if I understand you correctly

Do you mean you don't want player1 to cross to the other side?
If yes, I have two solutions

You can make an invisible border with a sprite block that can't be crossed. Or make a custom key movement for your player and give him a second condition (the following example subtracts half of the player x size - in this case 16 if the origin point is centered)

If pressed right
and
Player position.x <= windowwidth/2 - 16

  • System > On start of layout | system > load game from slot "brain"
  • System > On load failed | system > scroll to obj_Forum
B
17
S
8
G
5
Posts: 340
Reputation: 4,707

Post » Sun Mar 06, 2016 6:59 pm

thank you both for your replies...ill try them out.. I did try putting an invisible sprite in the center of the screen but I gave it a solid behaviour and that made the players stop but the Ball bounced off of it and just stayed on 1 half of screen
B
10
S
2
G
1
Posts: 23
Reputation: 693

Post » Sun Mar 06, 2016 7:35 pm

I would do something like this:

system every tick
- player1 set x = clamp(player.x,viewportleft(0), viewportleft(0)+0.5*(viewportright(0)-viewportleft(0))
- player2 set x = clamp(player.x, viewportright()-0.5*(viewportright(0)-viewportleft(0)), viewportright(0))
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sun Mar 06, 2016 8:48 pm

thanks LittleStain, that's done the trick :)
B
10
S
2
G
1
Posts: 23
Reputation: 693

Post » Sun Mar 06, 2016 9:00 pm

fr0z3n, your suggestion worked for my player 1 , it moved bout 3/4 way across its side of the screen but for player 2 , it moved past the center of screen and stopped equal with player 1s furthest point.

thanks again everyone for taking the time and your help :)
B
10
S
2
G
1
Posts: 23
Reputation: 693


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 23 guests