Fix hit detection
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=4 format=3 uid="uid://bt5rolsyjmx55"]
|
[gd_scene load_steps=5 format=3 uid="uid://bt5rolsyjmx55"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://bay1tvgtpfxns" path="res://Scenes/MeleeEnemySchmoove.tscn" id="1_0pxgq"]
|
[ext_resource type="PackedScene" uid="uid://bay1tvgtpfxns" path="res://Scenes/MeleeEnemySchmoove.tscn" id="1_0pxgq"]
|
||||||
[ext_resource type="Script" path="res://Scripts/MeleeEnemy.cs" id="1_50och"]
|
[ext_resource type="Script" path="res://Scripts/MeleeEnemy.cs" id="1_50och"]
|
||||||
@@ -6,13 +6,28 @@
|
|||||||
[sub_resource type="BoxShape3D" id="BoxShape3D_1nq5h"]
|
[sub_resource type="BoxShape3D" id="BoxShape3D_1nq5h"]
|
||||||
size = Vector3(0.470892, 0.604331, 0.423598)
|
size = Vector3(0.470892, 0.604331, 0.423598)
|
||||||
|
|
||||||
|
[sub_resource type="BoxShape3D" id="BoxShape3D_i1yvp"]
|
||||||
|
size = Vector3(0.470892, 0.604331, 0.423598)
|
||||||
|
|
||||||
[node name="MeleeEnemyOrb" type="Node3D"]
|
[node name="MeleeEnemyOrb" type="Node3D"]
|
||||||
|
|
||||||
[node name="CharacterBody3D" type="CharacterBody3D" parent="."]
|
[node name="CharacterBody3D" type="CharacterBody3D" parent="."]
|
||||||
|
collision_layer = 0
|
||||||
|
collision_mask = 0
|
||||||
script = ExtResource("1_50och")
|
script = ExtResource("1_50och")
|
||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="CharacterBody3D"]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="CharacterBody3D"]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.475385, 0.143401)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0840461, 0.475385, 0.143401)
|
||||||
shape = SubResource("BoxShape3D_1nq5h")
|
shape = SubResource("BoxShape3D_1nq5h")
|
||||||
|
|
||||||
[node name="meleeenemy - Updated" parent="CharacterBody3D" instance=ExtResource("1_0pxgq")]
|
[node name="meleeenemy - Updated" parent="CharacterBody3D" instance=ExtResource("1_0pxgq")]
|
||||||
|
|
||||||
|
[node name="Area3D" type="Area3D" parent="CharacterBody3D"]
|
||||||
|
collision_layer = 0
|
||||||
|
collision_mask = 2
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="CharacterBody3D/Area3D"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0840461, 0.475385, 0.143401)
|
||||||
|
shape = SubResource("BoxShape3D_i1yvp")
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="CharacterBody3D/Area3D" to="CharacterBody3D" method="OnHit"]
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ radius = 0.704872
|
|||||||
height = 1.67894
|
height = 1.67894
|
||||||
|
|
||||||
[node name="Pisces" type="CharacterBody3D" groups=["Player"]]
|
[node name="Pisces" type="CharacterBody3D" groups=["Player"]]
|
||||||
|
transform = Transform3D(0.33, 0, 0, 0, 0.33, 0, 0, 0, 0.33, 0, 0, 0)
|
||||||
script = ExtResource("1_tinf8")
|
script = ExtResource("1_tinf8")
|
||||||
_fireProjectile = ExtResource("2_ciujd")
|
_fireProjectile = ExtResource("2_ciujd")
|
||||||
_altFireProjectile = ExtResource("3_0of1i")
|
_altFireProjectile = ExtResource("3_0of1i")
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
[gd_scene load_steps=4 format=3 uid="uid://bq40xbqibrk1y"]
|
[gd_scene load_steps=6 format=3 uid="uid://bq40xbqibrk1y"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://Scripts/ShotgunBullet.cs" id="1_binxs"]
|
[ext_resource type="Script" path="res://Scripts/ShotgunBullet.cs" id="1_binxs"]
|
||||||
[ext_resource type="Texture2D" uid="uid://borp7xvlfdcmq" path="res://Textures/Projectiles/bubble.png" id="2_dv80m"]
|
[ext_resource type="Texture2D" uid="uid://borp7xvlfdcmq" path="res://Textures/Projectiles/bubble.png" id="2_dv80m"]
|
||||||
|
|
||||||
[sub_resource type="SphereShape3D" id="SphereShape3D_o6kys"]
|
[sub_resource type="CylinderShape3D" id="CylinderShape3D_eme14"]
|
||||||
radius = 0.2
|
radius = 0.3
|
||||||
|
|
||||||
|
[sub_resource type="CylinderShape3D" id="CylinderShape3D_752q2"]
|
||||||
|
radius = 0.3
|
||||||
|
|
||||||
|
[sub_resource type="CylinderShape3D" id="CylinderShape3D_ebbqv"]
|
||||||
|
radius = 0.3
|
||||||
|
|
||||||
[node name="ShotgunBullet" type="Node3D"]
|
[node name="ShotgunBullet" type="Node3D"]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.73894, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.73894, 0)
|
||||||
@@ -23,7 +29,7 @@ contact_monitor = true
|
|||||||
can_sleep = false
|
can_sleep = false
|
||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D"]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D"]
|
||||||
shape = SubResource("SphereShape3D_o6kys")
|
shape = SubResource("CylinderShape3D_eme14")
|
||||||
|
|
||||||
[node name="Sprite3D" type="Sprite3D" parent="RigidBody3D"]
|
[node name="Sprite3D" type="Sprite3D" parent="RigidBody3D"]
|
||||||
axis = 1
|
axis = 1
|
||||||
@@ -40,7 +46,7 @@ contact_monitor = true
|
|||||||
can_sleep = false
|
can_sleep = false
|
||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D2"]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D2"]
|
||||||
shape = SubResource("SphereShape3D_o6kys")
|
shape = SubResource("CylinderShape3D_752q2")
|
||||||
|
|
||||||
[node name="Sprite3D" type="Sprite3D" parent="RigidBody3D2"]
|
[node name="Sprite3D" type="Sprite3D" parent="RigidBody3D2"]
|
||||||
axis = 1
|
axis = 1
|
||||||
@@ -57,7 +63,7 @@ contact_monitor = true
|
|||||||
can_sleep = false
|
can_sleep = false
|
||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D3"]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D3"]
|
||||||
shape = SubResource("SphereShape3D_o6kys")
|
shape = SubResource("CylinderShape3D_ebbqv")
|
||||||
|
|
||||||
[node name="Sprite3D" type="Sprite3D" parent="RigidBody3D3"]
|
[node name="Sprite3D" type="Sprite3D" parent="RigidBody3D3"]
|
||||||
axis = 1
|
axis = 1
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ albedo_color = Color(0.584314, 0.0352941, 0.141176, 1)
|
|||||||
[sub_resource type="SphereMesh" id="SphereMesh_wuk0e"]
|
[sub_resource type="SphereMesh" id="SphereMesh_wuk0e"]
|
||||||
material = SubResource("StandardMaterial3D_phgri")
|
material = SubResource("StandardMaterial3D_phgri")
|
||||||
|
|
||||||
[sub_resource type="SphereShape3D" id="SphereShape3D_rokeu"]
|
[sub_resource type="CylinderShape3D" id="CylinderShape3D_3c0di"]
|
||||||
radius = 0.2
|
|
||||||
|
|
||||||
[node name="TestBullet" type="Node3D"]
|
[node name="TestBullet" type="Node3D"]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.538645, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.538645, 0)
|
||||||
@@ -20,7 +19,7 @@ _projectileSpeed = 15.0
|
|||||||
|
|
||||||
[node name="RigidBody3D" type="RigidBody3D" parent="."]
|
[node name="RigidBody3D" type="RigidBody3D" parent="."]
|
||||||
collision_layer = 34
|
collision_layer = 34
|
||||||
collision_mask = 32
|
collision_mask = 34
|
||||||
gravity_scale = 0.0
|
gravity_scale = 0.0
|
||||||
continuous_cd = true
|
continuous_cd = true
|
||||||
max_contacts_reported = 1000
|
max_contacts_reported = 1000
|
||||||
@@ -34,7 +33,7 @@ skeleton = NodePath("../..")
|
|||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D"]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D"]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0054872, -0.00215495, 0.0167444)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0054872, -0.00215495, 0.0167444)
|
||||||
shape = SubResource("SphereShape3D_rokeu")
|
shape = SubResource("CylinderShape3D_3c0di")
|
||||||
|
|
||||||
[node name="Sprite3D" type="Sprite3D" parent="RigidBody3D"]
|
[node name="Sprite3D" type="Sprite3D" parent="RigidBody3D"]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00168204, -0.0587139, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00168204, -0.0587139, 0)
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
public partial class MeleeEnemy : CharacterBody3D
|
public partial class MeleeEnemy : BasicEnemy
|
||||||
{
|
{
|
||||||
private float _speed = 1.0f;
|
[Export]
|
||||||
|
private float _speed = 0.4f;
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
@@ -12,9 +13,22 @@ public partial class MeleeEnemy : CharacterBody3D
|
|||||||
{
|
{
|
||||||
var convertedPlayers = players.Select(x => (Node3D)x);
|
var convertedPlayers = players.Select(x => (Node3D)x);
|
||||||
var target = convertedPlayers.OrderBy(x => Position.DistanceTo(x.Position)).FirstOrDefault();
|
var target = convertedPlayers.OrderBy(x => Position.DistanceTo(x.Position)).FirstOrDefault();
|
||||||
GD.Print(Position.DirectionTo(target.Position));
|
|
||||||
Position = Position.MoveToward(target.Position, _speed * (float)delta);
|
Position = Position.MoveToward(target.Position, _speed * (float)delta);
|
||||||
MoveAndSlide();
|
MoveAndSlide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public partial class BasicEnemy : CharacterBody3D
|
||||||
|
{
|
||||||
|
public void OnHit(Node3D node)
|
||||||
|
{
|
||||||
|
QueueFree();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DebugOnHit()
|
||||||
|
{
|
||||||
|
var node = new Node3D();
|
||||||
|
OnHit(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user