Nathan Laing
Member
Greetings,
I have attempted to implement the "Buttery Smooth Movement" wall collision tech blog project, using hspeed and vspeed instead of the single direction variable, with limited success; the object gets stuck in the wall.
Would anyone have any tips on how to fix it?
Nathan
I have attempted to implement the "Buttery Smooth Movement" wall collision tech blog project, using hspeed and vspeed instead of the single direction variable, with limited success; the object gets stuck in the wall.
Would anyone have any tips on how to fix it?
Code:
image_angle = point_direction(x, y, mouse_x, mouse_y);
acceleration = 1;
var xtarg = 0;
var ytarg = 0;
var _c = dcos(image_angle);
var _s = dsin(image_angle);
h_speed += acceleration * (keyboard_check(ord("W")) - keyboard_check(ord("S")));
v_speed += acceleration * (keyboard_check(ord("D")) - keyboard_check(ord("A")));
var xtarg = x + lengthdir_x(h_speed, image_angle);
var ytarg = y + lengthdir_y(v_speed, image_angle);
if (place_free(xtarg, ytarg))
{
x += _c * h_speed + _s * v_speed; // cos * hspeed + sin * vspeed
y += _c * v_speed - _s * h_speed; // cos * vspeed - sin * hspeed
}
else
{
var sweep_interval = 10;
for (var angle = sweep_interval; angle <= 180; angle += sweep_interval)
{
for (var multiplier = -1; multiplier <= 1; multiplier += 8)
{
var angle_to_check = image_angle + angle * multiplier;
xtarg = x + lengthdir_x(h_speed, angle_to_check) + _c * h_speed + _s * v_speed;
ytarg = y + lengthdir_y(v_speed, angle_to_check) + _c * v_speed - _s * h_speed;
if (place_free(xtarg, ytarg))
{
x = xtarg + _c * h_speed + _s * v_speed;
y = ytarg + _c * v_speed - _s * h_speed;
exit;
}
}
}
}
Nathan
Last edited: