D
Dieter
Guest
I'm pretty new to programming and gamemaker so I might be missing something very obvious here. I'm working on a small game and one of the spells is a ray of heat (like in Diablo). The beam shouldn't go through walls so I wrote some code that adjusts the size of the beam when it's hitting a wall. Sometimes it works correctly (although the beam flickers) but sometimes it becomes way to short. Through show_debug_message I noticed the problem: distance_to_object gives an incorrect distance. In the added screenshot you can see that it returns a value of 71 pixels, while the actual distance to the wall is 139px (I checked).
Does anyone have a clue what's going on here? The funny thing is, other collisions with the wall work pixel perfect (other spells, the player, etc).
Many thanks in advance!
Does anyone have a clue what's going on here? The funny thing is, other collisions with the wall work pixel perfect (other spells, the player, etc).
Many thanks in advance!
Code:
var ratio
var instwall
instwall = collision_line(x, y, x + beamendx, y + beamendy, obj_wall, false, true){
if instwall != noone{
ratio = distance_to_object(instwall) / lengthofbeam;
image_xscale = ratio;
show_debug_message("ratio is" + string(ratio));
show_debug_message("distance to wall is" + string(distance_to_object(instwall)))
} else {
image_xscale = 1;
}
}
Attachments
-
435.4 KB Views: 12