Added ship collisions
This commit is contained in:
@@ -1,18 +1,12 @@
|
||||
class_name EnemyController
|
||||
extends Node
|
||||
|
||||
@warning_ignore("unused_signal")
|
||||
signal accelerate(direction: Vector2, delta: float)
|
||||
|
||||
@warning_ignore("unused_signal")
|
||||
signal shoot(weapon_index: int)
|
||||
|
||||
|
||||
@warning_ignore("unused_signal")
|
||||
signal reload(weapon_index: int)
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func _physics_process(delta: float) -> void:
|
||||
for i in 10:
|
||||
shoot.emit(i)
|
||||
accelerate.emit(Vector2.ZERO, delta)
|
||||
|
||||
@@ -29,6 +29,7 @@ signal destroyed
|
||||
@export_range(0, 250) var acceleration : int = 0
|
||||
@export_range(0, 250) var deceleration : int = 0
|
||||
@export_range(0, 250) var max_speed : int = 0
|
||||
@export_range(0, 1000) var mass : int = 0
|
||||
|
||||
@export var weapon_positions: Array[Vector2]
|
||||
|
||||
@@ -47,6 +48,18 @@ func _ready() -> void:
|
||||
func _physics_process(_delta: float) -> void:
|
||||
var was_collided := move_and_slide()
|
||||
if was_collided:
|
||||
for i in get_slide_collision_count():
|
||||
var collider := get_slide_collision(i).get_collider()
|
||||
if collider is AbstractShip:
|
||||
var other_ship := collider as AbstractShip
|
||||
var momentum := mass * velocity
|
||||
var collider_momentum := other_ship.mass * other_ship.velocity
|
||||
var total_mass := mass + other_ship.mass
|
||||
|
||||
var new_velocity := (momentum + collider_momentum)/total_mass
|
||||
other_ship.velocity = new_velocity
|
||||
velocity = new_velocity
|
||||
|
||||
var normal := get_wall_normal()
|
||||
velocity -= normal.abs() * velocity
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
[node name="AbstractEnemyShip" groups=["enemies"] instance=ExtResource("1_28j6l")]
|
||||
collision_layer = 4
|
||||
collision_mask = 0
|
||||
collision_mask = 2
|
||||
script = ExtResource("2_fwvrd")
|
||||
|
||||
[node name="EnemyController" parent="." index="4" instance=ExtResource("3_l8c0n")]
|
||||
|
||||
@@ -15,6 +15,7 @@ script = ExtResource("2_3umer")
|
||||
acceleration = 30
|
||||
deceleration = 18
|
||||
max_speed = 60
|
||||
mass = 600
|
||||
weapon_positions = Array[Vector2]([Vector2(0, 16), Vector2(0, 0), Vector2(0, -16)])
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
|
||||
@@ -15,6 +15,7 @@ script = ExtResource("2_dgwiy")
|
||||
acceleration = 92
|
||||
deceleration = 46
|
||||
max_speed = 92
|
||||
mass = 250
|
||||
weapon_positions = Array[Vector2]([Vector2(0, 10), Vector2(0, -10)])
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
|
||||
@@ -14,6 +14,7 @@ script = ExtResource("2_bw04d")
|
||||
acceleration = 180
|
||||
deceleration = 80
|
||||
max_speed = 120
|
||||
mass = 100
|
||||
weapon_positions = Array[Vector2]([Vector2(0, 0)])
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
|
||||
@@ -13,10 +13,12 @@ height = 46.0
|
||||
|
||||
[node name="PlayerShip" groups=["players"] instance=ExtResource("1_6otxb")]
|
||||
collision_layer = 3
|
||||
collision_mask = 5
|
||||
script = ExtResource("2_625ti")
|
||||
acceleration = 92
|
||||
deceleration = 46
|
||||
max_speed = 92
|
||||
mass = 250
|
||||
weapon_positions = Array[Vector2]([Vector2(0, 8), Vector2(0, -8)])
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
|
||||
Reference in New Issue
Block a user