Log In  

Hi everyone,
I'm currently working on a game where multiple enemies (cubes) spawn in the corners of the screen, and then move towards the player. I also have what I call patterns, that are large rectangles moving along the screen. So I made this function that make the enemies collide with the pattern and bounce off it.
My problem is that some enemies just go through the pattern, or sometimes the opposite, bounce way too fast.
How would you guys handle stuff like this ?

-- this is called each frame when updating the enemies

-- r.x, r.y, r.w, and r.h are respectively the patterns location, width and height
-- dx and dy is the patterns directions
-- x,y, and s are respectively the enemies position and size
-- vx, and vy are the enemies velocity on each axis
if x+vx<r.x+r.w and
   x+s>r.x+dx and
   y+s>r.y+dy and
   y+vy<r.y+r.h then
 if x+vx<r.x then
 elseif x+vx+s>r.x+r.w then
 if y+vy<r.y then
 elseif y+vy+s>r.y+r.h then

-- this is to try and set a maximum value to the bounce
P#66353 2019-08-04 11:16

[Please log in to post a comment]