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.
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.
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.
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.
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?
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”.
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.
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.