What's wrong here?

What’s wrong here? The tank reaches the target and destroys it but doesn’t stop turning, while driving it turns towards the target but doesn’t stop turning

Is there only one enemy in the scene? If not, you might need to specify which enemy. Which direction is the tank animation facing? The image and angle might be out of sync. Zero degrees is towards the right, so the tank animation should also face right.

Edit: also once the enemy is destroyed, if there aren’t any enemies, it will still try to turn. It’s most likely using 0,0. If that’s the case then you could use the condition that checks the number of enemies on the scene. Or you could add a boolean variable to create an attack or idle state. IDK what is going to happen after an enemy is destroyed.

1 Like

@Keith_1357
there will be a lot of enemies on the stage that will appear from time to time, the main target are 3 cannons and I would like my units to go to their target but on the way when they come across foreign units they destroy them and when they do that they continue to go to the main targets, the first main target is cannon1 or cannon2, when one of them is destroyed they go to the closest one i.e. cannon3,

youtube video :
xx

As far as movement, I’d like to reverse things. Since it’s a tank, I would rotate the tank first and then apply force in the direction the tank is facing. It’s up to you if you want ths tank to be facing the target before moving. You can change the plus or minus variance as well as the turn speed.

Alternatively, you could use the pathfinder behavior.

As for targeting objects on the way, that would depend how the targets are destroyed. Does the tank only shoot in the direction it’s facing or does it fire in any direction? Does it aim with a spinning turret? Are there multiple guns? Maybe a main gun and smaller guns for the smaller enemies.

As for targeting, the larger targets can be put into a group. That way it would target the larger enemies first. You can then decide what to do with the smaller targets.

Again, it depends if the targeting and driving are seperate. You could change targets or stop and shoot or just shoot along the way.

Choose the nearest large target as long as there aren’t any smaller targets within a certain range.

This is a more advanced targeting. I used 2 targets but they could be groups. You might also want to check the distance to the larger target and only target the smaller when the tank is far away from a larger target. This is just an example. The object group has both objects in it.

You might prefer to use states or linking or some other method.

1 Like

@Keith_1357
I created 2 groups of objects, Playerunits and Enemies (I think more will be needed because different units will have different shooting distance, damage and there are 3 different cannons to destroy, I don’t know). Playerunits after appearing on the map (after clicking on e.g. tank (object block1) or mech (object block2) from the unit selection list on the left on the main screen when e.g. 10 sec for tanks and cost 100 gold, and 5 seconds for mech cost 50 gold) pass, they go to the target cannon1 on the left or cannon2 on the right (depending on where they appear in spawnPoint1 or 2) and on the way when they encounter enemies they attack them and when they destroy them they continue moving to cannons, when they destroy cannon1 or cannon2 they attack enemy units if there are any, or attack cannon3, when cannon3 is destroyed it is a win. The target of the units will be the first target encountered without exception. The missiles are fired from the front, so the unit must be aimed at the enemy. There will be upgrades such as, apart from the main weapon, e.g. in a tank - missles or something else, additional armor, attack and defense levels, etc. Only missles will fly at an angle to the target. Some units have, for example, 2 cannons or even 3. Can I ask you to write again how to do it because currently the tank turns about 90 degrees and starts moving in an arc and sideways as it turned.

Is the animation for the tank facing to the right. It might be out of sync with the angle. Zero degrees is right.

Otherwise, it would help to see your current events. I don’t have time right now to help but if you post the events someone else may. I’ll be online later tonight and if I can I’ll see if you still need help.

@Keith_1357 Thanks for answer! I recorded a video and by chance there is an error that appears very often, already at the beginning when the tank is moving it seems to freeze and stop for a few milliseconds and then moves to the target, it happens to me every 3-4 clicks preview, I don’t know if it’s that the tank freezes , the whole game or program. It only happens at the beginning.

VIDEO 2025 01 24 23 04 18

I don’t know what these are for. It’s applying force to 10 and rotating 11 degrees.

Your tank and bullets are sideways because 0 degrees is to the right. You need to rotate the images.

It should be

You can rotate the images in the editor under transform. You may need to change the points afterwards. Click the rotate button until the objects face to the right.

I don’t know if that fixes everything but it’s going to get you closer.

@Keith_1357 it works, thanks my friend!

1 Like