public static bool turnToPosition(this NPCProto proto, Vec3f position) { Vec3f direction = position - proto.Position; direction.Y = 0; proto.setDirection(direction); return(true); }
public static bool gotoPosition(this NPCProto proto, Vec3f position, float minDistance) { if (proto is NPC) { NPC p = (NPC)proto; if (p.NPCController == null)//set the position! { if (proto.getAI().lastPosUpdate == 0) { proto.getAI().lastPosUpdate = DateTime.Now.Ticks; } else { long now = DateTime.Now.Ticks; long time = now - proto.getAI().lastPosUpdate; float speed = (5 * 100) * (int)(time / 1000.0); Vec3f direction = position - proto.Position; if (direction.Length < speed) { proto.Position = position; } else { direction = direction.normalise(); direction *= speed; proto.Position = proto.Position + direction; } proto.getAI().lastPosUpdate = now; } } else { proto.getAI().lastPosUpdate = 0; } } if (proto.Position.getDistance(position) < minDistance) { return(true); } else { Vec3f p = position - proto.Position; p.Y = 0; proto.setDirection(p); proto.playAnimation(proto.getRunAnimation()); return(false); } }
public static bool turnTo(this NPCProto proto, Vec3f direction) { proto.setDirection(direction); return(true); }