So I finished the 2D Godot course and decided to work though a book I got from a humble bundle. One of the projects is an asteroids clone. Right now the project is just a Player Ship(rigidbody2D) and a bullet that is an Area2D.
Here is the functioning bullet script :
"
var bulletSpeed = 1000
var velocity = Vector2.ZERO
func start(_transform):
transform = _transform
velocity = transform.x * bulletSpeed
func _process(delta):
position += velocity * delta
"
When I first wrote this I was getting an error because I instinctively typed:
velocity.x = transform.x * bulletSpeed
And I’m just curious why that doesn’t work? Wouldn’t they all be floats within a Vector2? Also how does it know to put the float here: Vector2(transform.x, 0) But not here: Vector2(0, transform.x)
I’ve already experimented by adding : velocity = transform.y * bulletSpeed
And that over rides the the previous code creating this : Vector2(0, transform.y) causing the bullet to shoot out of the right side of the ship intead of forward.
Also if I add this : velocity += transform.y * bulletSpeed
Now the bullet shoots out at an angle and gives me this: Vector2(transform.x, transform.y)
But again how does it know?
And if I add this : velocity.y = transform.y * bulletSpeed I get a crash error. Why?
And last when I add velocity.y = 500 I don’t get any errors, but the bullet always shoots south in random directions.