Problem with object timer and movement variables

So, I’ve been working on a game in Gdevelop that involves a character with relatively simple movements. So far, I have already successfully created grid-based movement for my character, allowing it to move by its own height and width in a specific direction.

However, I’ve officially reached a roadblock when it comes to timers. I want my character to move by its own height and width, but I want it to do so on a timer so that I don’t have to continuously press the same key if I want it to keep moving in a single direction (in other words, I’m aiming for a simple press and release function for directions). In order to do so, I’ve created an object timer condition in addition to a trigger once condition with a start/reset action. Usually I merge this event with the directional event in order to get anything to happen at all.

One of my problems is the object timer. I’ve tried to get the time in seconds to be greater than or equal to my characters movement speed, and I’ve tried with Variable(move_r) but then my character only moves a few pixels before coming to a halt. The only time that ever changes is if I change the time in seconds to 0.021 seconds or more, but then we get to the second issue, which is the start/reset action. Even if my character moves all the way the timer won’t reset itself and the character won’t move unless I click the arrow keys again.

In short, I have no idea what I could be doing wrong. Mind you, I’m kind of a newbie when it comes to creating games and it’s pretty much a side hobby at this point, but I was wondering if anybody here knows what I’m doing wrong?

1 Like

I don’t know if this will help, but seeing as no one else has responded yet - I made a simple FSM for random AI movement, loosely based on what Doom’s monsters do, using a timer. Maybe it will help you.


Not surprising, seeing how it was only 12 minutes after the original post and a fair chunk of the world is tucked up in bed :smiley:

@Hallow, if I read your post correctly, you want the grid movement to be completed without the need for a key to be held down. If so, I’d suggest you look into tweens. Using a positional tween, you can set the destination position and the time you want the movement to take. The events would be along the lines of:


So I tried using your method MrMen, creating a new sprite and events for a test run but my character cannot move at all now. Is there a specific behavior I need? I tried adding the tweening behavior, but nothing changed.

The object will need the tween behaviour. Can you screen shot what you have done?

Those references to Player should be NewSprite2.

Well that explains it then XD
Unfortunately I can only move it once, and then it becomes unable to move after moving by its own width.

I have no problem with my events; my Player object moves as required.

Can you screen shot your latest events? And are those 2 events from your previous screen shot all there is? If there are more events, then please include them too.

Those two events are the only ones attached to this object. The only changes I’ve made was changing the references to new Sprite, as well as change the speed.

There has to be something else preventing the events from being actioned. Are there any parent events to these two events? Just providing a screen shot of the events you think are relevant doesn’t give me a picture of what’s going on; the events look fine, so there has to be something else stopping the movement events from kicking off.

In the event where you remove the tween, can you add an action to hide NewSprite2? Then when you preview the game, does NewSprite2 disappear after you press the right arrow key and the movement has finished?

Those two events have no parent events whatsoever. There are no other events tied to NewSprite2 at all.

And yes, if I add the action to hide NewSprite2 then it disappears as soon as the movement is over. Is that indicative of something?

It means the event is getting actioned.

To confirm, you press the right arrow key, NewSprite2 moves, you press the right arrow key a second time and NewSprite2 doesn’t move?

Do you have more than 1 NewSprite2 object in the scene? You can check this by opening the Instance List panel in the scene editor and searching for NewObject2.

Yes, that is correct. It moves the first time I click it, but not the second time.

I went to the instances list, and there is only one NewSprite2 on the list.

Ok, I’m stumped. Would you mind zipping up the project and making it available on a shared drive so I can download it and see what’s going on?

Okay, but I don’t actually know how to make a shared drive. Is there any chance we can continue this tomorrow or the day after? It’s getting late and I don’t know how much free time I have tomorrow.

Sure. Note, a shared drive is not something you’ll need to make. It’s a service like Google Drive, DropBox, MediaFire etc.

I’m so sorry I’m answering back over a month later. I got caught up with some irl stuff and had to set Gdevelop to the side. I don’t know if your still interested, but I’ve uploaded a .json file to a google drive if you still want to look at the project?

I can’t take a decent look right now, but possibly early next week. Either post or message a link to the file. If you post it, someone else may be able to help earlier than I can.