I've got a top down movement system implemented using the distance the mouse is away from the player and this collision technique. Which detects collision really well and i like the slippery aspect but at higher speeds I want objects to bounce off of each other and I'm having a lot of trouble implementing it.
I tried implementing this script but didn't have much success in getting it to work like it shows in the demo.
step:
move_obj
Any advice on how to create a bounce off of solid objects effect would be much appreciated.
I tried implementing this script but didn't have much success in getting it to work like it shows in the demo.
step:
Code:
#region Movement
var dir_x = mouse_x;
var dir_y = mouse_y;
var point = point_direction(x,y, dir_x,dir_y);
var mouse_dist = point_distance(x,y,mouse_x,mouse_y)
max_speed_point = camera_get_view_height(view_camera[0])/2 - 8
var speed_per = spd/max_speed
cur_speed_point = max(0,max_speed_point * speed_per)
var padding = 5;
rotate_towards(point,turn_speed)
#region change sprite based on turning
var mouse_ship_dif = angle_difference(point,image_angle)
switch (sign(mouse_ship_dif)) {
case 1:
var base_image = 2
break;
case -1:
var base_image = 4
break;
case 0:
var base_image = 0
break;
}
if image_index > base_image + 1 {
image_index = base_image
}
#endregion
if mouse_dist > cur_speed_point + padding {
spd = approach(spd,max_speed,acceleration)
} else if mouse_dist < cur_speed_point - padding {
spd = approach(spd, 1, acceleration)
}
if spd > max_speed {
spd -= acceleration;
}
if spd < 1 {
spd += acceleration;
}
move_obj(spd,image_angle)
Code:
/// @arg speed
/// @arg direction
var spd = argument0;
var dir = argument1;
var xtarg = x+lengthdir_x(spd,dir);
var ytarg = y+lengthdir_y(spd,dir);
if place_free(xtarg,ytarg) {
x = xtarg;
y = ytarg;
} else {
var sweep_interval = 10;
for ( var angle = sweep_interval; angle <= 80; angle += sweep_interval) {
for ( var multiplier = -1; multiplier <= 1; multiplier += 2) {
var angle_to_check = image_angle+angle*multiplier;
xtarg = x+lengthdir_x(spd, angle_to_check);
ytarg = y+lengthdir_y(spd, angle_to_check);
if place_free(xtarg,ytarg) {
x = xtarg;
y = ytarg;
exit;
}
}
}
}