I am making a platformer. I have my enemy shoots arrows. My player has the ability to make arrows fire back at the enemy, so in the collision with arrow event, I put a simple line of code:
hp-=15
but since I am using the following:
//Gravity
if place_free(x,y+1)
{
gravity=gravity_speed
gravity_direction=270
}
if !place_free(x,y+1)
{
gravity=0
gravity_direction=0
}
if !place_free(x,y-1)
{
move_bounce_solid(false)
}
if !place_free(x+1,y)
{
move_bounce_solid(false)
}
if !place_free(x-1,y)
{
move_bounce_solid(false)
}
//Define if the enemy_unit object exists
if instance_exists(enemy)
{
enemy=instance_nearest(x,y,enemy_unit)
}
//AI
if distance_to_point(enemy_unit.x,enemy_unit.y)<=hitrange and !collision_line(x,y,enemy_unit.x,enemy_unit,obj_ground,false,true)
{
//hit enemy
hspeed=0
show_message("Hitting")
moving=false
}
else
{
if distance_to_object(instance_nearest(x,y,obj_bow))<distance_to_object(enemy_unit) and hasbow=false
{
//pick up bow automatically
move_contact_solid(point_direction(x,y,instance_nearest(x,y,obj_bow).x,y),3)
moving=true
}
else
{
if distance_to_point(enemy_unit.x,enemy_unit.y)<=shootrange and hasbow=true and !collision_line(x,y,enemy_unit.x,enemy_unit.y,obj_ground,false,true)
{
//shoot enemy with bow (if it has one)
if floor(random(20))=0
{
[u]instance_create(x,y,obj_arrow)[/u]
}
moving=false
}
else
{
if distance_to_point(enemy_unit.x,y)>hitrange
{
move_contact_solid(point_direction(x,y,enemy_unit.x,y),3)
moving=true
if speed=0
{
if !place_free(x+move_speed*5,y) or !place_free(x-move_speed*5,y)
{
vspeed=-jump_speed
}
else
{
hspeed=0
moving=false
}
}
}
}
}
}
//Facing towards the player
if x<enemy_unit.x
{
image_xscale=1
right=true
}
else
{
if x>enemy_unit.x
{
image_xscale=-1
right=false
}
}
... The enemy takes damage when he fires.(yes, I'm using Lasse's AI example.)In my arrow object, in the create event, I have move_towards_point code which makes my arrow move.
I think the solution may be in the underlined snippet of code above.
is there perhaps a way to create the arrow a little away from the object?
thanks,
Rochowmaster.











