I'm trying to do a 3D monster AI, I've got two new D3D commands.
d3d_draw_spider_idle
d3d_draw_spider_walking
The only part of the AI code I've got is
if distance_to_object(obj_camera) <= 50;
How do make the AI code work if " if distance_to_object(obj_camera) <= 50; " is true then the spider will be in idle state but if False it will be walking to the player?
How do I do that.
Thanks, Sam
AI coding, I don't know what to do.
Started by Sharp Pixel Games, May 12 2012 12:28 PM
1 reply to this topic
#1
Posted 12 May 2012 - 12:28 PM
#2
Posted 12 May 2012 - 12:36 PM
Something like this should work:
EDIT: As per the manual, you should probably do it this way, rather than use distance_to_object() because unless your camera has a sprite or a mask, distance_to_object() will return undefined.
EDIT2: Edited because I forgot the x,y part of instance_nearest(). >.>
if (instance_exists(obj_camera)) {
camera = instance_nearest(x, y, obj_camera);
dist = point_distance_3d(x, y, z, camera.x, camera.y, camera.z)
if (dist <= 50) {
//walk to player
}
else {
//do nothing
}
}EDIT: As per the manual, you should probably do it this way, rather than use distance_to_object() because unless your camera has a sprite or a mask, distance_to_object() will return undefined.
EDIT2: Edited because I forgot the x,y part of instance_nearest(). >.>
Edited by johnki, 12 May 2012 - 01:15 PM.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











