Jump to content

Adding Unit Distance Detector


Intellect
 Share

Recommended Posts

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.

image.thumb.png.a5774ab55db9cc131351053e7c914832.png

Link to comment
Share on other sites

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.

image.thumb.png.a5774ab55db9cc131351053e7c914832.png

 

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.

  • Like 1
Link to comment
Share on other sites

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

  • Like 2
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...