This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

Laszer doesnt have a velocity when facing left direction can you may help me ?

Lovingsoul1337Lovingsoul1337 Posts: 3Member
edited June 2020 in Programming

Hey there good evening !

can you may help me with my lazerspear ? i want that i can add it to my player_atack_pos_left and player_atack_pos_right.

But if i do it for some reason if i face the leftside it dont gets velocity like you see in my gif.

I did change the pivot point for the sprite but i would need to do it for the collisionpolygon2D aswell is there a way ?

I did ask in the discord why it did not work they told me maybe because the flip_h of the sprite like you see in my code:

extends Node2D

enum DIRECTION {
    left = -1,
    right = 1
}

var direction

signal cooldown

onready var timer = $Timer
onready var animation_player = $AnimationPlayer
onready var sprite = $Sprite

export(int) var speed = 100
export(int) var cooldown = 1
export(int) var animationSpeed = 4

func _ready():
    animation_player.playback_speed = animationSpeed
    cooldown = animation_player.current_animation_length / animationSpeed - 0.1
    timer.wait_time = cooldown
    _switchScaleValues()

func _initialisation(dir):
    if dir == DIRECTION.right:
        direction = dir
    elif dir == DIRECTION.left:
        direction = dir

func _process(delta: float):
     position.x += (speed * delta) * direction

func _switchScaleValues():
    if direction == DIRECTION.left:
        sprite.flip_h = true
    else:
        sprite.flip_h = false

func _clear():
    queue_free()

func _on_Timer_timeout():
    emit_signal("cooldown")

and this is the code where i spawn it:

func ability():
    var instance = basic_light_atack.instance()
    instance._initialisation(direction)
    instance.connect("cooldown", self, "reset_ability_cooldown")

    if direction == DIRECTION.left:
        atack_point_left.add_child(instance)
    else:
        atack_point_right.add_child(instance)

can you may help me to fix this ?

thanks in advance !~~~~

https://i.imgur.com/kQe4pgS.gif

ps. did not find a way to highlight my code is there a code for it ? :)

Comments

  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin
    edited June 2020

    @Lovingsoul1337 said:
    ps. did not find a way to highlight my code is there a code for it ?

    There sis not, at least not with the plugin we are using currently. Additionally, you need to format your code with Markdown, not bbcode. Instead of adding [code][/code] instead you can indent all of the code with a single tab or add three ~ surrounding the text for it to be rendered as code :smile:

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.