Godot Version
godot-4
Question
Hi, I’m having trouble with the Camera2D node in Godot. I attached a Camera2D to the player, but the player can only move a little bit, and any other object moves in the opposite direction. I tried disabling the drag margin and the camera limits, but it didn’t help. Does anyone know how to fix this?
Node Tree
Player Code:
extends CharacterBody2D
var canon_ball_scene : PackedScene = preload("res://scenes/projectiles/canon_ball.tscn")
var can_fire_main_canon : bool = true
var can_fire_side_canon : bool = true
const speed = 400
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
var direction = Input.get_vector("left","right","up","down")
velocity = direction * speed
move_and_slide()
look_at(get_global_mouse_position())
var player_direction = (get_global_mouse_position() - position).normalized()
if Input.is_action_pressed("primary_action") and can_fire_main_canon:
var canon_ball = canon_ball_scene.instantiate() as RigidBody2D
canon_ball.position= $Markers/CanonLooseMarkerC1.global_position
canon_ball.linear_velocity = canon_ball.speed * player_direction
$"../Projectiles".add_child(canon_ball,true)
can_fire_main_canon = false
$CanonTimer.start(0.4)
if Input.is_action_pressed("secondary_action") and can_fire_side_canon:
var markers = $Markers.get_children()
for i in range(6):
var up_down_vector = Vector2.UP
if i >= 3:
up_down_vector = Vector2.DOWN
var canon_ball = canon_ball_scene.instantiate() as RigidBody2D
canon_ball.position = markers[i].global_position
var ship_angle = rotation
var canon_ball_velocity = up_down_vector.rotated(ship_angle).normalized()
canon_ball.linear_velocity = canon_ball_velocity * canon_ball.speed
$"../Projectiles".add_child(canon_ball,true)
can_fire_side_canon = false
$SideCanonTimer.start(0.5)
func _on_canon_timer_timeout():
can_fire_main_canon = true
func _on_side_canon_timer_timeout():
can_fire_side_canon = true