[SOLVED] move the character automatically without pressing any key on it

Hi there,…i am creating a game that needs to change the stage whenever the player complete it…i created 5 different collections in 5 different folders…(1 stage per each collection)…i think collection proxy is the key to achieve this…but how can i apply it to my game?..can you teach me exactly on how to solve my current problem…aand if possible can you give me a detailed instruction so that i can learn more and excel in game developing…any answer it very appreciated…thanks’

PS–i read the docu of collection proxy(coz i think its the key on my problem) but i cant exactly get it and i do not know how to apply it in the game…

Check out this thread. If you need more help just post another question. Level switch (change level)

@sicher hi sir…thanks for sending me that link…i think it will help me alot when ill get back in front of my pc later…but sir…i have one more question…i think you might see this like a silly question, as easy as piece of cake…but for me that new to defold its very important and i really need it in my simple game…so this is it:

I want my character (named hero.go) to move forward automatically on its own… and jump whenever i press the space key.i used your code of the hero frog from your endless runner tutorial…i pasted it on my hero script file…but when i run the game…my hero can actually jump…BUT it never move forward automatically by itself…i tried also to put some code in the function update(self, dt) to add velocity to my hero…and when i run the game…the hero can move forward by itself BUT it cant jump…i dont know the exact problem…i know that your skills and experience in game developing is more than to a competent so i know that you can help me to it…thanks and more power to you and to your team… :’)

Note: the ground in my game is not moving…so it looks like your simple platform game tutorial…but the only difference is i need my hero to move by itself forward and i will need to press the space key to jump…thats it…

Without the full source code it’s hard to tell what’s wrong, but doesn’t the Getting Started tutorial do exactly what you’re asking for? In this tutorial you have a constantly running frog that jumps when you tap the screen or press space. Examine the source code of this tutorial and compare it to your code.

You should have an update() function in a script attached to a game object that makes sure to move the ground and platforms every frame. And on your hero.go you need a script that acquires input focus and has an on_input() function that detects when you press the jump key.

@britzl no sir…the “getting started tutorial” and my game have some similarities…but the only difference between them is:

  • in the “getting started tutorial” - the ground is moving from right to left, while in my game, the ground isn’t need to move…

  • in the “getting started tutorial” - the hero frog plays the “running_right” animation (and as what i observed on it, the frog is NOT ACTUALLY RUN BY ITSELF…it only plays the running animation but actually it didn’t move in its current position(in left most edge), but instead the ground is moving for it.) ,… while in my game, i want my hero to actually move by itself forward (without pressing any key and without the ground scrolling)

actually, i used the same code of “hero.script” in the “getting started tutorial” coz it actually fits on my hero…but what i really cant get is that - i want my hero to move in the ground automatically by itself…when i used the code and run the game… my hero can jump whenever i pressed the space key,…but it didnt move on its current position,…so i tried to modify the hero.script…i tried to delete first this code “go.set_position(go.get_position() + self.velocity * dt)” and then replace this code to it ( in the function update(self, dt) :smile:

function update(self, dt)

   local speed = 300
local p = go.get_position()
p.x = p.x + speed * dt
go.set_position(p)

end

when i tried to run the game,…the frog can now run into the platform…BUT it cant jump from the ground…note that i actually set the frog on the ground (Y =30) …and whenever i change it’s position (Y = 130 and above) …it can actually run in the air without collision from the ground…so i think there is a problem in the code that i was used…can you guess whats the real problem that am i facing?..coz actually my brain is start to shrink right now… :smile: thanks for your time to read this and more power to you guys…

Ah, I see. I assume you want the level to be of a finite size? Should it be larger than a single screen (ie do you need to scroll)?

It sounds to me that what you need is more like a classic platformer a’la Super Mario? Have you looked at the Platformer tutorial?

@britzl yeah sir i want the ground has a finite size and i don’t want it to move/scroll (i managed to do that - thanks to the platformer tutorial, i already build an entire stage to my hero)…in super mario, the player have the ability to manipulate the movement of mario in the game (ie by pressing the right button of joystick, mario can run to the right…) but in my game…i want my hero to move by itself forward (to its right) without pressing any key on it… and thats my big problem…i dont know whats wrong onthe code i used…is there any missing code or something thta i need to put on?..

OH! OH!..sir thanks for all your help!.. i already found a way right now!.. for those who will encounter the same problem like mine,…here’s what i found a solution: in the hero.script file,…i modify the code to this:

-- apply velocity to the player character
local p = go.get_position()
p.x = p.x + 5 --you can put any number to it (speed)
go.set_position(p + self.velocity * dt)
1 Like