It doesn't repeat the same scenario

As the image shows when Goalkeeper collides with the ball, Player moves back to 115;238. After 5 seconds, the Goalkeeper kicks the with a permanent force of 300 pixels. This scenario only plays for once. For the second time the sprites in the scenario acts totally different. It doesn’t work in the way that I want.

What am I doing wrong?


Je pense que tu devrais lire Announcement around Timer Changes in 5.0.126 c’est peut être à cause de cela ?

1 Like

You need a trigger once, and to start and remove the timer “kball”. If you don’t remove (or reset and pause) the timer, then kball will keep increasing. Then the next time the ball is with the keeper, the keeper will ‘kick’ the ball straight away.

Something like :

You can also get away with resetting the timer and unpausing/pausing it instead of just resetting and deleting it, but for the sake of simplicity, I’m using reset and delete timer.

I’d also recommend you fill in the angles when adding forces. The actions may not work correctly otherwise.

1 Like

I did what you showed me. And I read Announcement around Timer Changes in 5.0.126 . It still don’t work the way I want. So I did this:

Now the Goalkeeper throws the Ball, and the Player catches but he doesn’t shoot back the ball after 6 seconds in the same way as the Goalkeeper.

You don’t have a timer for the player.

As you have the events now, if the player collides with the ball, the ball is kicked immediately. And then if the player id close to the post, the ball get booted. But there’s no time delay.

1 Like

Thank you :blush: I tried to put timer for Player but I failed.Can you show me where should I put the timer for Player?

Sure. But first you need to provide the conditions under which it should work. Does the player have to hold the ball for 6 seconds? Should it be 6 seconds from first touch? Is it just 6 seconds elapsed time no matter what?

I want the Player shoot the ball just 6 seconds elapse of time.

I’m taking this to mean since the start of the scene.

So you’ll want a timer, say call it “pkb” (player kick ball).

Reset timer pbk at the start of the scene

To the event when you check for collision between player and ball, add a subevent with a condition If scene timer "pkb" > 6.

To the same subevent, add the action reset timer "pkb" and add a permanent force to the ball.

That should be it.

1 Like

It doesn’t work. When the ball comes from the post after 6 seconds, Player kicks the ball immediately and goes along with the ball, not moves back to his position.

Yes, because you’ve got a timer running when the ball hits the post.

Yes, because you don’t have a timer running when the player collides with the ball

That’s correct. You’ve got a number of conflicting events :


Event 1 moves the player towards the ball if player is within 400 pixels of the ball.
Event 2 moves the ball towards the post if player is 250 pixels from the post
Event 3 is actioned when the ball is in touch with the post.

Event 3 will only fire if the player is within 250 pixels of the post. So the player moves back to the spot.
However, event 1 also gets actioned - if the player is within 250 pixels of the post (which is touching the ball) then the player is definitely within 400 pixels of the ball.

So events 1 and 3 are battling against each other, resulting in the player probably not doing anything.

Your next question will most likely be how to fix it. A solution I’d use would be finite states. Give the player an text object variable, and call it State. This can be “Move to ball”, “With ball” and “Move to position”. You can add states if needed, but these 3 seem to fir the events in the screen snip,

Then have a set of actions that are conditional on the player’s state. So event 1 would be conditional on player state being “Move to ball”, and event 3 would be conditional on plyer state being “Move to position”.

I have done exactly what you have said. It’s still doesn’t work. Am I missing something?

No, you haven’t, because I don’t think you quite understand how finite state machines work. Here’s an tutorial on it, though keep in mind this was written a much older version of GDevelop, but the concepts are the same.

And here’s another link to a post explaining finite state machines

So, what you want to be doing is something like the screen snip below. This is not exactly what you should be doing, but just an example to give you the general idea

And you need to ‘walk’ through your code to understand what it’s doing. For example, the first event you check if the state is “Move to ball” and then you set the state to “Move to ball” That’s never going to work unless you set the state to “Move to ball” elsewhere. Don’t just blindly put things in without considering what it’s doing.

1 Like