Jump to content


Photo

Moving Object Sliding Along Wall Not Random


  • Please log in to reply
10 replies to this topic

#1 enak101

enak101

    GMC Member

  • New Member
  • 11 posts

Posted 01 February 2010 - 10:24 AM

I am making an avoidance game where you are a soccer ball and there are lots of bombs and you must survive until you get a set amount of points each level. As the level progresses more and more bombs are appearing.

My problem is that the bombs collide with the wall and just slide along the wall instead of bouncing off it in a random direction. I have tried setting the bombs to bounce off the walls but its not random enough. I just want the bombs to bounce randomly off walls to make it more difficult.

Thanks,Novice Game Maker
  • 0

#2 onpon4

onpon4

    GMC Member

  • GMC Member
  • 1175 posts
  • Version:GM8

Posted 01 February 2010 - 11:46 AM

Well, I don't recommend "random" bouncing because it's confusing to a player and can be very frustrating. However, if you want it to be "random" (I assume you mean a random direction) then do the following:

If the collision is to the right or left, execute this:
vspeed = irandom_range(min,max);

Replace min and max with the min/max possible values. If you don't use GM8, use this code instead:
vspeed = floor(random(2*max))-max;

The min value will automatically become the -max (i.e. if you choose 4, the min becomes -4).

For top/bottom collisions, just replace yspeed with xspeed:
hspeed = irandom_range(min,max);
hspeed = floor(random(2*max))-max;

And there. You've got random bouncing. But again, I suggest you don't do this. It could prove to be quite frustrating. Just make the bombs bounce off.

Edited by jaychant, 02 February 2010 - 05:10 AM.

  • 0

#3 enak101

enak101

    GMC Member

  • New Member
  • 11 posts

Posted 02 February 2010 - 03:39 AM

Well, I don't recommend "random" bouncing because it's confusing to a player and can be very frustrating. However, if you want it to be "random" (I assume you mean a random direction) then do the following:

If the collision is to the right or left, execute this:

yspeed = irandom_range(min,max);

Replace min and max with the min/max possible values. If you don't use GM8, use this code instead:
yspeed = floor(random(2*max))-max;

The min value will automatically become the -max (i.e. if you choose 4, the min becomes -4).

For top/bottom collisions, just replace yspeed with xspeed:
xspeed = irandom_range(min,max);
xspeed = floor(random(2*max))-max;

And there. You've got random bouncing. But again, I suggest you don't do this. It could prove to be quite frustrating. Just make the bombs bounce off.



I am sorry but i dont know how to tell if a colision is to the left right top or bottom... could you let me know please
  • 0

#4 enak101

enak101

    GMC Member

  • New Member
  • 11 posts

Posted 02 February 2010 - 03:44 AM

i tried putting both the codes into the collision event but the exact same thing happened.
  • 0

#5 onpon4

onpon4

    GMC Member

  • GMC Member
  • 1175 posts
  • Version:GM8

Posted 02 February 2010 - 05:08 AM

Sorry, I accidentally typed "xspeed" and "yspeed". They should have been hspeed and vspeed.

Use this action before changing horizontal speed:
:)

Put in "hspeed" for the value and check the Relative box.

If that returns true, you hit a wall vertically. So under this, set the horizontal speed:
::lmao::
to "irandom_range(min,max)" or "floor(random(2*max))-max" if you are not using GM8. Be sure to replace max and min with their respective values. Also, if you reverse the vertical speed, move that action to here.

Use the Else action for the horizontal collision:
;)

And set the vertical speed to "irandom_range(min,max)" or "floor(random(2*max))-max" (be sure to replace max and min with their respective values). If you reverse the horizontal speed, move that action to here.

Edited by jaychant, 02 February 2010 - 05:19 AM.

  • 0

#6 enak101

enak101

    GMC Member

  • New Member
  • 11 posts

Posted 02 February 2010 - 05:18 AM

umm sliding along wall still.. i put the circle command in the create of bomb and the else in collision event
  • 0

#7 onpon4

onpon4

    GMC Member

  • GMC Member
  • 1175 posts
  • Version:GM8

Posted 02 February 2010 - 05:20 AM

umm sliding along wall still.. i put the circle command in the create of bomb and the else in collision event


No, put them both in the same event, the collision event. These are conditionals. Using "else" by itself will do nothing.
  • 0

#8 enak101

enak101

    GMC Member

  • New Member
  • 11 posts

Posted 02 February 2010 - 05:24 AM

hmm i dont want the bombs to move along the walls at all only bounce off but problem with th e in game bounce is that it will just go up down up down up down i want it to be random and just not slide at all... possible do i need code?

so can i only set them to move diagonally off walls is that the only way i can not make them move along walls?

Edited by enak101, 02 February 2010 - 05:25 AM.

  • 0

#9 onpon4

onpon4

    GMC Member

  • GMC Member
  • 1175 posts
  • Version:GM8

Posted 03 February 2010 - 05:04 AM

No, put the bounce action before those actions I gave you. The entire point of what I gave you is to change the hspeed or vspeed to make it "random", as you put it.

Alternatively, reverse horizontal/vertical direction in the places I indicated.

Edited by jaychant, 03 February 2010 - 05:04 AM.

  • 0

#10 saim

saim

    GMC Member

  • GMC Member
  • 1086 posts

Posted 03 February 2010 - 07:31 PM

Sliding along the wall usually is because it collided and got into the sprite. Try jumping to xprevious and yprevious before doing anything.
  • 0

#11 enak101

enak101

    GMC Member

  • New Member
  • 11 posts

Posted 03 February 2010 - 08:49 PM

ah ive got this solved anyway thanks guys

sorry if i didnt understand yous the best pretty new to it still. Now to powerups hehe
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users