N
nired360
Guest
Hi everyone , am having a problem with my enemy chase ai, i've used the tile collision code from heart beast's tile collision video and it's been working very well, i copied the player movement code and used it on my enemy object (took out the keyboard inputs ), but whenever i try to code in the chase ai , the enemy speeds out of the level no matter how much his speed is set to in "the move_towards_point" command
here is the tile collision code for my enemy object :
// create event
velocity_ = [0, 0];
gravity_ = 1.5;
max_velocity_ = [8, 32];
var layer_id = layer_get_id("collis");
collision_tile_map_id_ = layer_tilemap_get_id(layer_id);
// step event
var vector2_x = 0;
var vector2_y = 1;
//hmovement
velocity_[vector2_x] = clamp(velocity_[vector2_x], -max_velocity_[vector2_x], max_velocity_[vector2_x]);
//fr
//gravity
velocity_[vector2_y] += gravity_;
//moveand contacttiles
move_and_contact_tiles(collision_tile_map_id_, 64, velocity_);
veclocity_[vector2_x] = clamp(velocity_[vector2_x], -max_velocity_[vector2_x], max_velocity_[vector2_x]);
//jumping
var on_ground = tile_collide_at_points(collision_tile_map_id_, [bbox_left, bbox_bottom], [bbox_right-1, bbox_bottom]);
and here's the simple chase ai i used
//step event
if distance_to_object(play) < 40
{
direction = (move_towards_point(play.x,play.y,2));
}
here is the tile collision code for my enemy object :
// create event
velocity_ = [0, 0];
gravity_ = 1.5;
max_velocity_ = [8, 32];
var layer_id = layer_get_id("collis");
collision_tile_map_id_ = layer_tilemap_get_id(layer_id);
// step event
var vector2_x = 0;
var vector2_y = 1;
//hmovement
velocity_[vector2_x] = clamp(velocity_[vector2_x], -max_velocity_[vector2_x], max_velocity_[vector2_x]);
//fr
//gravity
velocity_[vector2_y] += gravity_;
//moveand contacttiles
move_and_contact_tiles(collision_tile_map_id_, 64, velocity_);
veclocity_[vector2_x] = clamp(velocity_[vector2_x], -max_velocity_[vector2_x], max_velocity_[vector2_x]);
//jumping
var on_ground = tile_collide_at_points(collision_tile_map_id_, [bbox_left, bbox_bottom], [bbox_right-1, bbox_bottom]);
and here's the simple chase ai i used
//step event
if distance_to_object(play) < 40
{
direction = (move_towards_point(play.x,play.y,2));
}