Intellect Posted May 30, 2020 Report Share Posted May 30, 2020 Hey all. Can anyone help me design a piece of code to allow units to detect the distance between themselves and an enemy unit and queue a specific animation. Check these units, they are animating through the wall, but I just want them to trigger at the contact point. Quote Link to comment Share on other sites More sharing options...
Lion.Kanzen Posted May 30, 2020 Report Share Posted May 30, 2020 Add minimum distance to attack, i guess. Quote Link to comment Share on other sites More sharing options...
asterix Posted May 30, 2020 Report Share Posted May 30, 2020 3 hours ago, Intellect said: Hey all. Can anyone help me design a piece of code to allow units to detect the distance between themselves and an enemy unit and queue a specific animation. Check these units, they are animating through the wall, but I just want them to trigger at the contact point. 2 hours ago, Lion.Kanzen said: Add minimum distance to attack, i guess. Like @Lion.Kanzen said if you look at how AI and pathfinder operates it is on the same premise. 1 Quote Link to comment Share on other sites More sharing options...
bb_ Posted May 30, 2020 Report Share Posted May 30, 2020 Calculating the distance between two units is fairly easy: The distance between the centres of two units can be computed by querying the position components and ask for the exact positions of the units. If you want to compute the distance between a unit (with obstruction, like you have with the walls) and a point or another unit, you should be able to use one of the following functions in the obstructionManager: /** * Returns the distance from the obstruction to the point (px, pz), or -1 if the entity is out of the world. */ virtual fixed DistanceToPoint(entity_id_t ent, entity_pos_t px, entity_pos_t pz) const = 0; /** * Calculate the largest straight line distance between the entity and the point. */ virtual fixed MaxDistanceToPoint(entity_id_t ent, entity_pos_t px, entity_pos_t pz) const = 0; /** * Calculate the shortest distance between the entity and the target. */ virtual fixed DistanceToTarget(entity_id_t ent, entity_id_t target) const = 0; /** * Calculate the largest straight line distance between the entity and the target. */ virtual fixed MaxDistanceToTarget(entity_id_t ent, entity_id_t target) const = 0; You can query them from JS using Engine.QueryInterface(SYSTEM_ENTITY, IID_ObstructionManager).fooDistancefoo(foos) Hope this helps 2 Quote Link to comment Share on other sites More sharing options...
Intellect Posted June 1, 2020 Author Report Share Posted June 1, 2020 On 5/30/2020 at 3:22 AM, bb_ said: Calculating the distance between two units is fairly easy: The distance between the centres of two units can be computed by querying the position components and ask for the exact positions of the units. If you want to compute the distance between a unit (with obstruction, like you have with the walls) and a point or another unit, you should be able to use one of the following functions in the obstructionManager: /** * Returns the distance from the obstruction to the point (px, pz), or -1 if the entity is out of the world. */ virtual fixed DistanceToPoint(entity_id_t ent, entity_pos_t px, entity_pos_t pz) const = 0; /** * Calculate the largest straight line distance between the entity and the point. */ virtual fixed MaxDistanceToPoint(entity_id_t ent, entity_pos_t px, entity_pos_t pz) const = 0; /** * Calculate the shortest distance between the entity and the target. */ virtual fixed DistanceToTarget(entity_id_t ent, entity_id_t target) const = 0; /** * Calculate the largest straight line distance between the entity and the target. */ virtual fixed MaxDistanceToTarget(entity_id_t ent, entity_id_t target) const = 0; You can query them from JS using Engine.QueryInterface(SYSTEM_ENTITY, IID_ObstructionManager).fooDistancefoo(foos) Hope this helps Thanks! Im still a bit confused as far as the specifics go. Could I pm you for more elaboration? Thanks! Quote Link to comment Share on other sites More sharing options...
bb_ Posted June 1, 2020 Report Share Posted June 1, 2020 You can pm or ask here and ping me (the latter has the advantage that everyone can benefit) 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.