How to make an object aim another object until it delete in gdevelop

hi guys
how to make an object(A) aim another object(B) until it delete in gdevelop, rework that action after that object(B) is delete
thanks

We need more details. Do you have any events that you can post?
Is this top down? Are you using any behaviors like platform or physics?
A picture of the game or a description of what obj a and b represent would also help.


i have 3 knight and 3 elf, i want each of them pick random an object and dont change the target after they pick, and aim that target until that target get kill (delete) then they gonna chose another target,

i also want the darknight and elf alway face by face and have distance about 70px( same position Y and position X±70)
can u help me to let me know how to do it please Mr Keith
thanks

Locking would be easy enough. pick the nearest enemy, link the player and enemy. You might want to set a player and enemy Boolean variable like Locked to true. Although, the linking might be enough.

You then pick the enemy linked to the player and attack. The tougher part is deciding if multiple objects should lock onto each other and handling other issues.

Try me (There are no interactions, although the objects are draggable)
https://gd.games/keith_13579/reflective-zephyr

Project: Click the green [CODE] button and [download zip] then unzip and open Json file.
https://github.com/doug13579/gdevelop-Lock-on-enemiess

This is one way to do it. There could be better ways.

There are 3 objects. Enemy, Player and a shapePainter for the visual.
The shape painter’s “draw the shapes relative” is unchecked.
The enemy has the health behavior and they both have the drag behavior

I don’t know about that part. Maybe one issue at a time. Or someone else can help on that part.

thanks for help me, now i know how to lock enemy with allies now

1 Like

You’re welcome. As fir the 2nd issue. We might need more info. Are those characters enemies or allies?


I want they can move like this face to face, and the dark knight(allies), enemy is elf, can you help me that how should i do it pls, I cant image the way I do now :sweat_smile:

like both of them can find the way to make them same Y and ±70 X position

I don’t know how to make that type of movement. It’s not my genre.

I think i find the way to do it, I will do it tonight but sir can you tell me how your code game play work(link object) i do exactly the same of you but i still not really understand how it work
Please tell me sir

https://wiki.gdevelop.io/gdevelop5/all-features/linked-objects/#linked-objects

Linking creates a link or reference between objects. You can’t link objects of the same type, meaning enemy to enemy but you can link multiple enemies to multiple players. Sometimes you need to add a 2nd object to work as a connector between the same object but not when using different objects.

Once linked you pick the linked objects with the
Take into account all object linked to object. You can then use conditions or actions that refer to just those linked objects.

The linking order isn’t important but the check for links order is. Think of it like a family tree. You can link the children to their parents but you can only link 1 set of objects at a time. 1 instance per object. Like 1 child to 1 parent. The linking order doesn’t matter. It’s a 2 way link. You can link child to parent or parent to child.

The object names when picking the linked objects is important because it picks all of the objects linked to the 2nd object. So, you can pick the linked children to a specific parent or pick the parents linked to a specific child. You can then do something with the picked objects or narrow the selection with more conditions or you can use a for each object to cycle through the objects.

It sounds the same but it’s the direction up or down in the family tree. You can then unlink them either as a set or unlink all of the objects. Again, you can only unlink 1 set of objects at a time. Unless you use unlink all objects form this object. Even then it’s 1 particular instance meaning unlink any children linked to a specific parent.

It’s not just restricted to creating a link between 2 objects. You can link any number of object to any number of other objects. You just can’t link 2 of the same object. Parent to child. Parent to cousins. Cousins to aunts. It can be as simple or complex as it’s needed. Too many links might become more of a confusing spider web than a family tree.

Some people say it’s good housekeeping to unlink objects before they are deleted. IDK if that’s true but I usually do just to be safe.

I hope that helps.

I still not get it :smiling_face_with_tear:, like how it work exactly and what it impact the function and action

I’m going to over explain it because I don’t know your skill level or exactly which concept that your having trouble with. To be honest, instances and linking took me a while to fully grasp. I learned by creating a lot of test projects.

Let’s start with the basics. Just in case.

Without any actions all jnstances of an object are basically picked. Any condition or action applies to all of the instances of an object.

Conditions pick matching objects with conditions like whether it’s object is visible or an object variable or using the picking condition.

Once picked you can use further conditions to narrow the list. If there are any objects still picked then the actions and subevents get triggered. You might start with hundreds of objects and end with the same amount or a smaller amount or even just 1.

Each new event starts with a fresh pick list. Sub events inherent their parent pick lists. They create their own pick lists that get used by an sub events of them. As events get processed. It goes to new lists and returns to previous list. Events with the same indentation share the same list as their sub events unless they have conditions which alter the list.

My example goes through the players list whose object boolean lockedOnTarget is false
It picks the closest enemy. It then links the Player and enemy and sets the player object boolean lockedOnTarget to true, this prevents the object from being assigned another target and let’s the next section know to move it toward the object it’s linked to.

The 2nd section picks the objects whose object variable lockedOnTarget is true. There could be multiple players, so we use for each object.

We can only link 1 enemy to each player but there could be multiple players linked to the same enemy.

We go thru each player and pick the enemy linked to it. We then move the player towards the enemy.

The last section checks if the players are in collision with the enemy. It picks all of them. So, you might have 2 players and 2 enemies or 3 players and 1 enemy. Should the objects collide at the same exact frame.

After applying damage to all of the enemies
The for each object goes through the players.
The players could theoretically kill multiple enimes and since you can’t do some actions with multiple objects you use a 2nd for each object to go through the enemies.
It then checks if the enemy is dead.
If the enemy is dead it wants to pick the linked players but because of the for each player only 1 player is currently picked. So, before picking the linked players. It needs to pick all of the players.

This picks all of the players. It’s a sub-event, so it doesn’t mess with the for each object pick list.

The players linked to the dead enemy are picked so every picked player object variable lockedOnTarget is set back to false. This flags the first event group to pick a new target. For safety sake, we unlink all onkects from the dead enemy.

The cycle then repeats.

If there’s a concept that you’re still unsure of. Let me know specifically what part you’re having trouble with and I’ll try to help.

Ahhh i think i got it, i just join gdevelop about 1 week :sweat_smile:, i understand all of it, but still not get the mean of link function for

Like if without the link what will happen, can you explain for me please

If you try to pick linked objects and there are none then nothing happens. Nothing gets picked and the actions aren’t triggered.

Without any conditions then any action would apply to all of the instances of the object.
Conditions work like filters. It starts with all of the instances and either picks all of them, picks some of them or picks none of them. If no objects are picked then nothing happens. (Under most instances. There are exceptions)

You might start with 50 objects.
You check if the objects are visible
That leads you with 30
You check if their X() position is less than 200
You now have a pick list with 10 objects
You can then do something with those 10 objects or continue adding conditions.

Conditions can only pick the objects that previous conditions picked unless you use pick all objects or it’s the first condition in an event.

oh i see, thank you mr Keith

1 Like

new update to do this action is, we can use pathfinding extension for this

Once an object is picked you can use any condition or action.

1 Like