How to access variables in all instance besides the one colliding with collision event

D

DanyIsCome

Guest
I'm having an issue with my infinite runner. The game spwans "obstacles" that the player moves with the arrow keys. I'm using the collision event in order to make the obstacles stop when colliding with the player. The problem is that GMS adresses variables on 1 v 1 basis during the collision event. That way the only obstacle who stops is the one that directly collides with the player character and not every obstacle instance in the room.
How can I fix this?
 
J

joqlepecheur

Guest
For exemple, with collision event with a wall par_wall, use "with", not "other"

with par_wall
{
speed = 0 ;
}
 
D

DanyIsCome

Guest
For exemple, with collision event with a wall par_wall, use "with", not "other"

with par_wall
{
speed = 0 ;
}
That doesn't work :(
The fact is that the character has a fixed height and can move horizontally while the obstacles can only move vertically. Does the command speed in your statement modify every instance of par_wall even if the collision event is in the character?
 
J

joqlepecheur

Guest
how are your walls moving vertically ?
a custom variable or built-in or a hard coded value (y += something) ?

with keyword should access all instances
 
D

DanyIsCome

Guest
how are your walls moving vertically ?
a custom variable or built-in or a hard coded value (y += something) ?

with keyword should access all instances
I'm using a script to check which key is select.
The script sets a variable called mdirection to a certain value. In the character there's a step event like this

///Movement and animation
scr_checkDirection() //sets mdirection based on key pressed
switch mdirection{
case 0: //Stop
hspeed=0
obj_wallPar.vspeed=0
background_vspeed[0] = 0
break
case 1: //Right
hspeed=3
background_vspeed[0] = 0
obj_wallPar.vspeed=0
break
case 2: //Up
hspeed=0
background_vspeed[0] = 3
obj_wallPar.vspeed=3
break
case 3: //Left
hspeed=-3
background_vspeed[0] = 0
obj_wallPar.vspeed=0
break
case 4: //Down
hspeed=0
background_vspeed[0] = -3
obj_wallPar.vspeed=-3
break
}
 
J

joqlepecheur

Guest
maybe you could replace obj_wallPar.vspeed=0 by with obj_wallPar vspeed = 0 ?
 
In your player collision event with the obstacle object:

Code:
var _totalObstacles = instance_number(obj_obstacle);
for(var i = 0; i < _totalObstacles; i++){
  var _obstacle = instance_find(obj_obstacle, i);
  if(_obstacle != other){
    //stop the _obstacle here
    //_obstacle.speed = 0 or whatever you do to stop it
  }
}
 
J

Jamsawamsa

Guest
I think an easy way to implement this, albeit a little inelegant might be to use a global variable, and have all of the obstacle instances reference this global variable. That way when u set the global speed to 0 it should affect all other objects referencing it.

Do correct me if Im wrong, but ill test it out for u and see if it works
 
Top