D
Den
Guest
So I'm not making any type of path finding thing, just more of a: when an enemy is chasing the player it jumps up to the player or over a obstacle.
I have some code I was trying but I can't get it to work at all, the chase and the collisions work fine but the jump part doesn't and I don't understand why.
Here's all the code involved
The enemy's Step event :
The Chase State
I have some code I was trying but I can't get it to work at all, the chase and the collisions work fine but the jump part doesn't and I don't understand why.
Here's all the code involved
The enemy's Step event :
Code:
///Move The Enemy
script_execute(scr_chase_state);
//Apply gravity
if (place_meeting(x, y+1, obj_solid)) {
vspd += grav;
}
//Horizontall collisions
if (place_meeting(x+hspd, y, obj_solid)) {
hspd = 0;
}
//Move Horizontally
x += hspd
//Virtical collions
if (place_meeting(x, y+vspd, obj_solid)) {
while (!place_meeting(x, y+sign(vspd), obj_solid))
{
y+= sign(vspd);
}
vspd = 0;
}
//Move virtically
y+= vspd;
The Chase State
Code:
///scr_chase_state()
//Get the distance from the mouse
if (point_distance(x, y, mouse_x, y)>16) {
if (x < mouse_x)
{
hspd = 4;
}else {
hspd = -4;
}
}else {
hspd = 0;
}
//Set up jump check vars
var on_ground = place_meeting(x, y+1, obj_solid);
var mouse_above = (mouse_y < y);
var wall = place_meeting(x+hspd, y, obj_solid);
var xpos = x+sign(hspd);
var ypos = y+(sprite_height/2)+1;
var ledge = !instance_position(xpos, ypos, obj_solid);
//Check for jump
if (on_ground && mouse_above && (wall || ledge)) {
vspd = -jspd;
}