Godot Version
4.1.3.stable
Question
I’m trying to figure out how to make my bullet go in the right direction when facing right
this is my player code
extends CharacterBody2D
@export_group("Player Variables")
@export var speed = 1200
@export var jump_speed = -1800
@export var gravity = 4000
@export_range(0.0, 1.0) var friction = 0.1
@export_range(0.0 , 1.0) var acceleration = 0.25
@export var Bullet: PackedScene
func _physics_process(delta):
velocity.y += gravity * delta
#getting input direction
var dir = Input.get_axis("left", "right")
#moving and sliding
if dir != 0:
velocity.x = lerp(velocity.x, dir * speed, acceleration)
else:
velocity.x = lerp(velocity.x, 0.0, friction)
#flipping sprite to the movement direction
if dir > 0:
%Sprite2D.flip_h = true
elif dir < 0:
%Sprite2D.flip_h = false
move_and_slide()
#jumping
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = jump_speed
#shooting
if Input.is_action_just_pressed("shoot"):
shoot()
func shoot():
var b = Bullet.instantiate()
owner.add_child(b)
b.transform = %BulletSpawner.global_transform
this is my bullet code
extends Area2D
var speed = 750
func _physics_process(delta):
position += transform.x * speed * delta
func _on_body_entered(body):
queue_free()
I’m very new to programming and especially Godot. I figured out how to get my character to look left and right when moving with the if loop- but I’m not sure how to make the marker2d and direction of the bullet move too as the marker2d doesn’t have a flip variable and neither does the characterbody2d and those were my two ideas on how to make this happen. Am I just completely missing it? Thanks in advance.