#How do I get the ground to loop infinitely?

71 messages · Page 1 of 1 (latest)

willow lark
#

Been following this tutorial but I got stuck because the code wasn't working
https://www.youtube.com/watch?v=nKBhz6oJYsc

I used a tilemap to make the ground section, that's the only thing I did differently

Learn the basics of Godot by making a side scroller game from scratch.

The code for the game is built from scratch and will re-create all the features of the t-rex game. This will use a parallax background node to create the scrolling background with a 3D effect. I'll have a spawner to generate enemies as well as collision detection.

Code and ...

▶ Play video
wintry snow
#

@willow lark anything you want to parallax that is a 2d canvas node ie.. sprite, tilemap, place as a child of the parallax layer.

willow lark
#

I was thinking of trying that, I just assumed there was a reason why they didn't just use the same thing for the background and the ground

#

hold on

#

I just put the sprite with the already looping background, idk how to keep the collision static tho

wintry snow
#

If you're not really moving the player and only the background, just use a static body that is solid under the player. Then scrolling the tilemap would just be aesthetics.

#

You're wanting them to jump bodies in a static shape, but you don't necessarily need static bodies. For example, I have a scrolling background in a flappy bird clone I did, the bird only moves up and down of course, the background scrolls and pipes that are areas move from code.

#

I'm pretty sure though, I did this a long time ago and it worked fine, the tilemap static shape should still collide in a parallax layer, but not something I've tested recently. I'm currently away from com, but I can work in a scrolling tilemap test shortly to see if I can help you resolve it

wintry snow
#

This is all I do to scroll the level.

func _process(delta):
    $ParallaxBackground.set_scroll_offset(Vector2($ParallaxBackground.scroll_offset.x - (30 + level) * delta, 0))
    
#

I use level for speed modifier.

willow lark
#

thanks, gonna try doing it from scratch to see what I missed

wintry snow
#

Good luck, if you need any help you can ping me.

willow lark
#

@wintry snow

#

can we call? I could try sharing my screen

wintry snow
#

I'm not really setup to help that way. I can try to diagnose with screen shots and code.

willow lark
#

aight hold on

#

thanks btw

wintry snow
#

No problem.

willow lark
#

this is the script for the main node, I've been stuck trying to figure out the last bit

#

I've been trying to get the ground to move back to its original position each time it moves and passes a certain limit, idk what's not working

#

code for player character

#

basically trying to make the chrome dinosaur game, but i'm stuck on the making the ground loop

#

main scene

wintry snow
#

Did you setup the tilemap in the parallax layer?

willow lark
#

i made a png for the ground so I could put it in a sprite2d node instead

wintry snow
#

In the demo I showed, you won't need to move anything other than the player jumping up and down.

willow lark
#

when I tried including it in the parallax layer, the collision also moved and the character fell anyways

#

the ground did end up looping, but the collision didn't

wintry snow
#

So, you want the player to jump chasms, and objects, but also need the ground to collide?

willow lark
#

should I be using 4.2.1?

wintry snow
#

You should use what you are comfortable with. Most work the same with few differences.

#

What version are you using?

willow lark
#

4.2.1

wintry snow
#

That's what I am using.

#

So let's see if we can work this out....

#

It may be best in this case to allow the actual movement to happen by the player, but forced through code rather than input. So they could still jump, but they will have a constant velocity to the right....

#

The level could still parallax the BG if desired.

willow lark
#

i'll try moving the ground sprites to the the parallax background

wintry snow
#

You could draw the whole level in parallax and it'll repeat. I'm not sure why the collisions didn't carry with them.

willow lark
#

ground is looping now

#

but im not sure where I should be putting the collisions to make em repeat

#

the character just falls eventually

wintry snow
#

I will run another test real quick.

willow lark
#

okk

wintry snow
#

So, my collision did carry through the advanced scene.

willow lark
#

how'd you do it?

wintry snow
#

The size of your parallax layer, is where the tilemap will repeat.

#

The speed of the parallax offset.

willow lark
#

how do you add the collision?

wintry snow
# wintry snow

So if you wanted the gap to repeat every 20 steps, for 30 turns inside your parallax layer would have to match those positions to repeat.

#

To the right where it says physics layer, if blank, choose add new element.

wintry snow
wintry snow
willow lark
#

like this?

wintry snow
#

Yes

willow lark
#

still falls

wintry snow
#

Ensure that the player is recognizing the collision layer

willow lark
#

how do i do that

wintry snow
#

If you didn't change it, it'll default to 1. Click the character body and look at the collision layer.

willow lark
#

yeah

wintry snow
#

Are you scrolling the parallax layer like I suggested?