0
\$\begingroup\$

I had a problem with detecting my character's collision with the enemy being detected in 2 ways:

  • side by side
  • when it (character) jumps into the enemy's head.

I imagine it to be basic, so I figured this question would be not only on the site but also in countless other places.

I researched this site and found related things, but not exactly what I would like:

Getting 2D Platformer entity collision Response Correct (side-to-side + jumping/landing on heads)

Handling exact collisions on character controller and/or other objects in unity? (eg. head shot, chest , leg,etc)

But because of this video I got it:

https://www.youtube.com/watch?v=9LbutnLIj84


The game I'm doing is platform, but instead of the character move, it's the platform that moves.

obj_Plataform - Step Event:

if jump==false{
    if !place_meeting(x,y+1,obj_Player){
        vspeed=-5;
    }else{
        vspeed=0;
    }
}else{
    if contJump<20{
        contJump+=1;
    }else{
        jump=false;
        contJump=0;
    }
}

This is a code that causes the platform to go up when it is not in contact with the player.

And it has a condition for the platform jump (it goes down and the jump variable becomes true, and after the counter reaches a certain value the jump variable becomes false).

My problem is that the character can not get into the platform by colliding on the side with it (The character is the white cube):

enter image description here

I thought about using place_meeting in relation to the x-axis, but the whole platform is just an object (error), because I do not know if it would be possible to move some of dozens of tiles at the same time in the correct way.

Plataform:

enter image description here

I also tried something related in a collision event among those involved, including using the character's x, but nothing worked.

I thought a condition to prevent the platform from walking left while it is colliding with the character.

obj_Plataform - Keyboard Event (left arrow):

x-=10;

Above the current code to move the platform to the left.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Today I understood a little more about the function place_meeting.

Documentation:

https://docs.yoyogames.com/source/dadiospice/002_reference/movement%20and%20collisions/collisions/place_meeting.html

obj_Plataform - Keyboard Event (left arrow):

if !place_meeting(x-7,y+3,obj_Player){
    x-=10;
}

With this code you prevent the platform from moving to the left if any part of it is colliding with the character.

Two important points:

  • activate precise collision checking on the platform sprite.

enter image description here

  • by adding a y-axis value (y+3), you give the platform a chance to move even if the character is a bit sunk in it.

enter image description here

Value varies from project to project.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .