this post was submitted on 18 Oct 2023
2 points (100.0% liked)

Godot

5848 readers
17 users here now

Welcome to the programming.dev Godot community!

This is a place where you can discuss about anything relating to the Godot game engine. Feel free to ask questions, post tutorials, show off your godot game, etc.

Make sure to follow the Godot CoC while chatting

We have a matrix room that can be used for chatting with other members of the community here

Links

Other Communities

Rules

We have a four strike system in this community where you get warned the first time you break a rule, then given a week ban, then given a year ban, then a permanent ban. Certain actions may bypass this and go straight to permanent ban if severe enough and done with malicious intent

Wormhole

!roguelikedev@programming.dev

Credits

founded 1 year ago
MODERATORS
 

Hey y'all, throwing a little project together in Godot 4.1 to practice stuff I learned after a tutorial project. I've set up two markers as my projectile spawn points, but the shots are spawning slightly off from the markers and I can't figure out why. Code and pics below. ~~I "fixed" it by shifting the player sprite2D 5 pixels to the right. Not sure why the spawns are being offset though.~~ NVM that only fixed it at the starting position, the shots are way off when rotating. In editor you can see the markers at the two tips on the ship.

In game you can see the shots spawning just to the side of the markers.

Edit: I broke the formatting posting on mobile ๐Ÿ™ƒ

This snippet is from the player script

` var player_direction = (Globals.player_pos - $FixedHardpointDirection.position).normalized()

if Input.is_action_just_pressed("fire_primary") and can_shoot and Globals.laser_ammo > 0 and hardpoint_type == 0:

	Globals.laser_ammo -= 1

	var hardpoint_positions = $ShotStartPositions.get_children()

	can_shoot = false

	$Timers/LaserTimer.start()

	for i in hardpoint_positions:

		player_shot_fixed_weapon.emit(i.global_position, player_direction)

`

And this is from the level script

` func _shoot_fixed_weapon(pos, direction):

var laser = laser_scene.instantiate() as Area2D

laser.position = pos

laser.rotation_degrees = rad_to_deg(Globals.player_rotation)

direction.x = cos(Globals.player_rotation)

direction.y = sin(Globals.player_rotation)

Globals.fixed_hardpoint_direction = Vector2(direction.x,direction.y)

print(Globals.fixed_hardpoint_direction)

laser.direction = Globals.fixed_hardpoint_direction.rotated(-1.5708)

$Projectiles.add_child(laser)

`

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here