| Attention | Topic was automatically imported from the old Question2Answer platform. | |
| Asked By | Synnlaw |
My character can shoot rockets and they travel in the right direction depending on what direction my player is facing but the sprite refuses to flip_h when shooting left and it looks like the rocket is traveling backways.
Just trying to understand where I need to put my code to make the rocket sprite flip_h depending on what direction my player is facing and what code specifically I would need to write.
I am a noob, sorry if it sounds like a basic question, I am not very good yet, I am trying to understand though!
Character rocket code:
var direction = 1
const FIRE = preload(“res://Fire.tscn”)
func shoot():
if Input.is_action_just_pressed(“fire”) and not is_near_wall():
var direction = 1 if not $Sprite.flip_h else -1
var f = FIRE.instance()
f.direction = direction
get_parent().add_child(f)
f.position.y = position.y
f.position.x = position.x + 30 * direction
Rocket code:
extends KinematicBody2D
var velocity = Vector2()
var direction = 1
const SPEED = 800
const GRAVITY = 3
const BOUNCE = -300
func _ready():
velocity.x = SPEED * direction
func _physics_process(delta):
velocity.y += GRAVITY
if is_on_wall():
queue_free()
velocity = move_and_slide(velocity,Vector2.UP)
func _on_VisibilityNotifier2D_screen_exited():
queue_free()
func _on_Timer_timeout():
$AudioStreamPlayer.play()