I've had a search and find some results but I suspect they are from older versions of Godot because they refer to commands that no longer exist.
I am writing a space shooter that exists in infinite space. By that I mean that the player can travel any distance in any direction with the camera fixed to them. However, if any non-player sprite (rigidBody) strays too far from the player (and therefore camera) they should be teleported to other side of the player. Obviously, as well as changing their position I also want to retain the physics forces applied to them.
This is what I have so far but it isn't working. Can anyone suggest where it is going wrong or perhaps a better solution?
var distx = player.position.x - position.x
var disty = player.position.y - position.y
var av = angular_velocity
var lv = linear_velocity
var teleported = false
if distx > wrapRange:
position.x = player.position.x + wrapRange
teleported = true
elif distx < -wrapRange:
position.x = player.position.x - wrapRange
teleported = true
if disty > wrapRange:
position.y = player.position.y + wrapRange
teleported = true
elif disty < -wrapRange:
position.y = player.position.y - wrapRange
teleported = true
if teleported:
apply_impulse(position, lv)
apply_torque_impulse(av)
Thanks :)