Fixed ship collision size

This commit is contained in:
2025-11-07 14:26:54 +03:00
parent d9f0d80b18
commit 0740570263
+18 -8
View File
@@ -2,18 +2,14 @@ extends CharacterBody2D
@onready var sprite := $Sprite2D @onready var sprite := $Sprite2D
@onready var colision := $CollisionShape2D @onready var collision := $CollisionShape2D
@export var size : Vector2: @export var size : Vector2:
set(value): set(value):
size = value size = value
if sprite and sprite.texture: _update_texture_size()
sprite.texture.size = value _update_collision_shape()
if colision:
colision.shape.radius = 0.9 * minf(size.x, size.y)/2
colision.shape.height = 0.9 * maxf(size.x, size.y)
colision.rotation = 0.0 if size.x < size.y else PI/2
get: get:
return size return size
@@ -30,9 +26,11 @@ extends CharacterBody2D
func _ready() -> void: func _ready() -> void:
var texture := PlaceholderTexture2D.new() var texture := PlaceholderTexture2D.new()
texture.size = size
sprite.texture = texture sprite.texture = texture
_update_texture_size()
_update_collision_shape()
const GATLING = preload("res://game/entities/weapons/gatling_gun/gatling_gun.tscn") const GATLING = preload("res://game/entities/weapons/gatling_gun/gatling_gun.tscn")
const RAILGUN = preload("res://game/entities/weapons/railgun/railgun.tscn") const RAILGUN = preload("res://game/entities/weapons/railgun/railgun.tscn")
var weapons_by_offset := { var weapons_by_offset := {
@@ -81,3 +79,15 @@ func shoot(weapon: Node) -> void:
func reload(weapon: Node) -> void: func reload(weapon: Node) -> void:
if weapon in weapons: if weapon in weapons:
weapon.reload() weapon.reload()
func _update_texture_size() -> void:
if sprite and sprite.texture:
sprite.texture.size = size
func _update_collision_shape() -> void:
if collision:
collision.shape.radius = 0.9 * minf(size.x, size.y)/2
collision.shape.height = 0.9 * maxf(size.x, size.y)
collision.rotation = 0.0 if size.x < size.y else PI/2