• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Windows Can someone help me with better collisions?

M

Marmil321

Guest
Hey,
I'm new to coding.

i watched a youtube video about making a 2d game.
but the collisions is not how i want them.


this is my code
codehelp.JPG

as you can see in the video the character stops when he's head hits the black bars.
I want it to stop at his feet.

like this.
LikeThis.JPG
(this is photoshoped, if you are wondering)

Please help me with the code.
Thanks :)
 
Try adding this in the collision event with the wall:
Code:
if y > place_meeting(x,y,obj_wall).y-sprite_get_height(sprite_index)/2 && vsp == 0 //works  if  origin is centered
     y = place_meeting(x,y,obj_wall).y-sprite_get_height(sprite_index)/2;
This is pretty basic, I'm sure someone can give you a more neat solution, but this is where I would start from. You can consider it 'code for thought' :).
 
D

Dennis Ross Tudor Jr

Guest
One option is to make your bounding box smaller. Go into the sprite mask and only use a rectangle the size of his feet and maybe some of his ankle. Also you can set the (Y) origin to where his feet is. Otherwise you'll have to adjust for the distance between the (Y) origin and the location on teh sprite you want it to be able to accept past the limit
 

Slyddar

Member
Also when you post code on the forum, look for the code button and paste it in that way. Makes it easier for people to help.

 
Top