RyanC
Member
Hi everyone, does anyone have any ideas how this code can be optimized, as it's eating up 30% off my game time.
I normally make the step frequency less frequent but when I do this my enemies are jumping off the floor and don't move smoothly.
Code:
/// movement and collsion
alarm[2] = 1 // step frequency
// gravity
if ! place_meeting(x,y+grav,obj_floor) {
gravity = grav
}
else {
gravity = 0
vspeed = 0
if grav move_contact_all(270,24) else move_contact_all(90,24)
y-=grav // move off floor to use faster code below
}
var xtarg = x+lengthdir_x(move_speed,move_dir);
var ytarg = y+lengthdir_y(move_speed,move_dir);
if ! place_meeting(xtarg,ytarg,obj_floor) {
x = xtarg;
y = ytarg;
}
else {
vspeed = -move_speed*image_yscale
}
I normally make the step frequency less frequent but when I do this my enemies are jumping off the floor and don't move smoothly.