Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Dava |
I’m trying to make a scene where the player is walking in a field. The player will be moving with the camera, and thanks to that, the field and the sky will be moving; with parallax background the field will be moving faster than the sky or vice versa, I am trying to make the player be able to move faster/slower than the camera but if the player tries to leave the camera from the left, right, or bottom, the player wouldn’t bypass it, but if the player tries to leave the grass, the same thing I tried implementing this in such:
- Node2D
- Player
- ParallaxBackground
- ParallaxLayer
- field
- sky
- ParallaxLayer
- Camera (current=true)
then in the Node2D script:
# I have already done the player input code in the player scene
extends Node2D
onready var player = get_node("player")
onready var camera = get_node("camera")
func _ready():
set_process(true)
pass
func _process(delta):
camera.position.x += 5
player.position.x += 5
if(player.position.x > camera.position.x): # player shouldn't leave from the right
player.position.x = camera.position.x
if(player.position.x < camera.position.x - camera.position.x): # player shouldn't leave from the left
player.position.x = camera.position.x - camera.position.x
if(player.position.y > camera.position.y): # player shouldn't leave from the bottom
player.position.y = camera.position.y
if(player.position.y < WhateverTheHighestPointOfTheGrassIs.y): # player shouldn't leave the grass
player.position.y = WhateverTheHighestPointOfTheGrassIs.y
pass
pass
Everything is just messed up and the background doesn’t move plus the fact that the camera doesn’t even show the background
Help is much appreciated!