0 votes

I'm making a 2d platformer where the character you play as has a gun.
But whenever I shoot to the left, it goes really slowly.
When I shoot to the right it's completely fine.

Does anyone know how to fix this?

in Engine by (15 points)

Hi! you really need to share your code so we can help! Its hard to know what is happening if we cannot see the relevant code.

Sorry about that

Here is the bullet's code \/\/\/

`extends KinematicBody2D

var speed = 1000
var dir
var pos
var velocity = Vector2()
var accel
var loop = 1
var shooty

func _ready():
dir = Pewww.shooty
pos = self.position.x
self.position = Pewww.pos
shooty = Pewww.shooty

func process(delta):
velocity.x += speed * delta
velocity.y += Pewww.change.y
velocity.x = velocity.x * shooty
move
and_slide(velocity)

if loop == 1:
    loop = 2
    yield(get_tree().create_timer(1.0),"timeout")
    queue_free()

And here is Pewww, the thing that the Bullet's code takes some stuff from

extends Node

var direction = 1
var shooty = 1
var pos = Vector2.ZERO
var change = Vector2()

func process(delta):
if Input.is
actionjustpressed("uileft"):
shooty = -shooty
if Input.is
actionjustpressed("ui_right"):
shooty = abs(shooty)

1 Answer

+2 votes
Best answer

With velocity.x += speed * delta you add a positive value to your velocity vector. So the velocity increases when shooting to the right as expected, but decreases (by adding a positive number to a negative velocity) when shooting to the left. So the value is already wrong when you try to fix the direction with velocity.x = velocity.x * shooty. Removing these two lines and writing velocity.x += (speed * delta) * shooty instead should fix the issue.

by (1,696 points)
selected by

That fixed it! Thank you very much!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.