#Screen wrapping?

8 messages · Page 1 of 1 (latest)

hazy pebble
#

heya for my asteroids clone I want asteroids that go off the screen on one side to come back on the opposite side, how could I calculate the opposite side of the screen from a node's current postion?

golden flower
#

This is very complicated, let me tell you as I tried it before. Especially if you want parts of the asteroid still visible on the one side while it's already starting to appear on the other

#

Then there are collision concerns when 'teleporting' the asteroids and so on. I think I would have come up with a system eventually but even with a lot of experience writing games and in godot it would have taken me a lot of time to get it right.
It becomes more and more complicated the deeper you dive in possible solutions, with strange edge cases around the corners for example. There really isn't an easy&good solution here imo.

#

Or maybe I just went down the completely wrong path from the start 😂

#

I was using Rigidbodies for asteroids and ship tho. Maybe it's possible to come with a easier solution that doesn't use built-in physics

flint cliff
#

I went for

extends RigidBody2D
...
var game_area:Vector2 = Vector2(1920, 1024)

func _process(delta):
    wrap_screen()

func wrap_screen():
    var p_before = position

    if position.x < 0:
        position.x += game_area.x
    elif position.x > game_area.x:
        position.x -= game_area.x

    if position.y < 0:
        position.y += game_area.y
    elif position.y > game_area.y:
        position.y -= game_area.y

    printt(p_before, position)

but somehow physics seems to ignore these 'new' values. I somehow same something about "physics uses global values" but have to figure that out now.

flint cliff
golden flower
# flint cliff I went for ``` extends RigidBody2D ... var game_area:Vector2 = Vector2(1920, 10...

you'll have to use _integrate_forces() if you want to manipulate a Rigidbody2D in this way. I'd suggest making [the first iteration of] your game with non-colliding asteroids because this will get way more complicated than just positional screen-wrapping and using viewports.
I think what this guys does is good example:
https://www.youtube.com/watch?v=FmIo8iBV1W8

Get my Godot 4 course: http://eepurl.com/hhftjT

In this tutorial series you will learn how to make a steroids style game in Godot 4.

Support and get access to the source code: https://www.patreon.com/kaanalpar
Instagram: https://www.instagram.com/kaanalpar/
Udemy: https://bit.ly/3YKQzWu
Skillshare: https://www.skillshare.com/en/user/kaanalpar
...

▶ Play video