Windows [SOLVED] falling spikes

yvodlyn

Member
Hello everyone,
I wrote this code to make spikes falling when the player goes below the spikes. However, they didn't fall when the player goes below them. Can someone help me?

Here the code:
step event:
gravity_direction = 270;

if (!collision_line(x,y,x,obj_player.y,obj_solid,false,true)) {
if (obj_player.x = self.x) {
gravity = 0.05;
}
}

if place_meeting(x,y+1,obj_solid) {
instance_destroy();
}
 
D

DarthTenebris

Guest
collision_line() doesn't return a boolean. It returns an instance id. Check for != noone instead.

Hope I helped :)
 
What @Fat_Man3468800 said.

Another thing you might consider changing is that the player x and ice x may not ever line up exactly. For example, if your player has a speed of 4, his x position will only ever be multiples of 4. It's probable that your code will still work, but you leave yourself open to the possibility that they will be one pixel off and the ice won't activate. I would recommend doing something like

if (abs(player.x-x)) < 4)

instead. Note also, you do not need to use the term "self" basically ever. In this case, just "x" will work, it assumes it's talking about itself without the self attached.
 

TheouAegis

Member
You can use collision_line as a Boolean. If an instance is found, it's true, if not it's false. noone is always evaluated as false in gamemaker. Instance IDs are always evaluated as true. The one version in which this was not the case was deemed a bug by the programmers themselves.

The issue was, as stated, the x coordinates are never the same. You should check if the absolute value of the difference between the x coordinates is less than some arbitrary value such as 4.
 

Bingdom

Googledom
What TheouAegis said.

When a value is >= 0.5, it is evaluated as true. Since instance id values are >= 10000 (or 1000), it would be evaluated as true if there was a collision. Since noone is -4, it would be false.
 

yvodlyn

Member
What @Fat_Man3468800 said.

Another thing you might consider changing is that the player x and ice x may not ever line up exactly. For example, if your player has a speed of 4, his x position will only ever be multiples of 4. It's probable that your code will still work, but you leave yourself open to the possibility that they will be one pixel off and the ice won't activate. I would recommend doing something like

if (abs(player.x-x)) < 4)

instead. Note also, you do not need to use the term "self" basically ever. In this case, just "x" will work, it assumes it's talking about itself without the self attached.
Thxt a lot... It work!!!
 
Top