• 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!

Store Last Object Collided With Before One Currently Colliding With

The player needs to pass through a series of objects that are lined up next to each other. The behavior must change based on the last object it collided with, and the current object it has entered.

How I keep the variable last_collide from writing the same value as new_collide once I start to collide with the second object?

Once the player hits a third object last_collide should change to the value of the 2nd object, and new_collide should change to the value of the third. Note that the vars shouldn't change unless there's a new instance collided with, and that the player may collide with 2 objects at once when moving between the objects. The player never collides with 3 or 4 of these objects at once. The collision objects are up against each other but not stacked on top of each other.
 

Phil Strahl

Member
I can't quite wrap my head around it, especially with the lack of code, so sorry if my reply is useless to you. How about storing the IDs of the objects the player collided with in a list or an array. With each new collision, you check whether the new colliding instance is already in the list and if not, add it to this list?
 
I can't quite wrap my head around it, especially with the lack of code, so sorry if my reply is useless to you. How about storing the IDs of the objects the player collided with in a list or an array. With each new collision, you check whether the new colliding instance is already in the list and if not, add it to this list?
The code below doesn't have last_obj or new_obj since I'm not sure where to put them yet. The variables here change every step so I'll probably need to set them in the create event, and find some way to prevent them from constantly changing, but still change when they need to. This script is in the End Step.

//for collsion test while loop
obj_id=noone
//how many obj collisions
obj_col_count=0
//whether only 1 object collsion occurs
single_obj=false

//parent object to check

with (argument0)
{
//set obj_id to colliding instance add obj_col_count if collision

obj_id=place_meeting(x+argument1,y+argument2,other.id)
if obj_id!=noone
{
obj_col_count+=1
}
}

//only 1 obj in player bounding box

if obj_col_count==1
{
single_obj=true
}
else
{
false
}
 
Last edited:
Top