Link CAN hit
This commit is contained in:
30
Scenes/TestBullet.tscn
Normal file
30
Scenes/TestBullet.tscn
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
[gd_scene load_steps=5 format=3 uid="uid://si4byubqnng4"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://Scripts/TestBullet.cs" id="1_cavby"]
|
||||||
|
|
||||||
|
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_5vpcx"]
|
||||||
|
albedo_color = Color(0.584314, 0.0352941, 0.141176, 1)
|
||||||
|
|
||||||
|
[sub_resource type="SphereMesh" id="SphereMesh_wuk0e"]
|
||||||
|
material = SubResource("StandardMaterial3D_5vpcx")
|
||||||
|
|
||||||
|
[sub_resource type="SphereShape3D" id="SphereShape3D_rokeu"]
|
||||||
|
|
||||||
|
[node name="TestBullet" type="Node3D"]
|
||||||
|
script = ExtResource("1_cavby")
|
||||||
|
_projectileSpeed = 5.0
|
||||||
|
|
||||||
|
[node name="RigidBody3D" type="RigidBody3D" parent="."]
|
||||||
|
collision_layer = 0
|
||||||
|
gravity_scale = 0.0
|
||||||
|
continuous_cd = true
|
||||||
|
contact_monitor = true
|
||||||
|
|
||||||
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="RigidBody3D"]
|
||||||
|
transform = Transform3D(0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, 0, 0, 0)
|
||||||
|
mesh = SubResource("SphereMesh_wuk0e")
|
||||||
|
skeleton = NodePath("../..")
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D"]
|
||||||
|
transform = Transform3D(0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, 0, 0, 0)
|
||||||
|
shape = SubResource("SphereShape3D_rokeu")
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
[gd_scene load_steps=4 format=3 uid="uid://b38hcomu4tpm5"]
|
[gd_scene load_steps=5 format=3 uid="uid://b38hcomu4tpm5"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://Scripts/TestCharacter.cs" id="1_hddqi"]
|
[ext_resource type="Script" path="res://Scripts/TestCharacter.cs" id="1_hddqi"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dtyujwnb6w3kv" path="res://Models/TestModels/link.gltf" id="1_rwdbt"]
|
[ext_resource type="PackedScene" uid="uid://dtyujwnb6w3kv" path="res://Models/TestModels/link.gltf" id="1_rwdbt"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://si4byubqnng4" path="res://Scenes/TestBullet.tscn" id="3_ojvu2"]
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_fqik1"]
|
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_fqik1"]
|
||||||
radius = 0.152487
|
radius = 0.152487
|
||||||
@@ -10,6 +11,7 @@ height = 0.456443
|
|||||||
[node name="Character" type="CharacterBody3D"]
|
[node name="Character" type="CharacterBody3D"]
|
||||||
script = ExtResource("1_hddqi")
|
script = ExtResource("1_hddqi")
|
||||||
_speed = 2.0
|
_speed = 2.0
|
||||||
|
_attackPattern = ExtResource("3_ojvu2")
|
||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||||
transform = Transform3D(0.999665, -0.0258978, -7.10543e-15, 0.0258978, 0.999665, 0, 0, 0, 1, 0, 0.19703, 0)
|
transform = Transform3D(0.999665, -0.0258978, -7.10543e-15, 0.0258978, 0.999665, 0, 0, 0, 1, 0, 0.19703, 0)
|
||||||
@@ -18,4 +20,4 @@ shape = SubResource("CapsuleShape3D_fqik1")
|
|||||||
[node name="Pivot" type="Node3D" parent="."]
|
[node name="Pivot" type="Node3D" parent="."]
|
||||||
|
|
||||||
[node name="link" parent="Pivot" instance=ExtResource("1_rwdbt")]
|
[node name="link" parent="Pivot" instance=ExtResource("1_rwdbt")]
|
||||||
transform = Transform3D(-10, 0, 8.74228e-07, 0, 10, 0, -8.74228e-07, 0, -10, 0, 0, 0)
|
transform = Transform3D(10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0)
|
||||||
|
|||||||
@@ -19,9 +19,13 @@ shape = SubResource("BoxShape3D_dk0pn")
|
|||||||
mesh = SubResource("BoxMesh_eaper")
|
mesh = SubResource("BoxMesh_eaper")
|
||||||
|
|
||||||
[node name="Camera3D" type="Camera3D" parent="."]
|
[node name="Camera3D" type="Camera3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, -0.118128, 5.82113, -1.13346)
|
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, -0.118128, 8.18686, -1.13346)
|
||||||
fov = 40.0
|
fov = 40.0
|
||||||
|
|
||||||
|
[node name="DebugCamera" type="Camera3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 0.821149, 0.570714, 0, -0.570714, 0.821149, -0.36148, 1.40359, 0.864433)
|
||||||
|
visible = false
|
||||||
|
|
||||||
[node name="Link" parent="." instance=ExtResource("1_fwf6c")]
|
[node name="Link" parent="." instance=ExtResource("1_fwf6c")]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
||||||
|
|
||||||
|
|||||||
22
Scripts/Projectile.cs
Normal file
22
Scripts/Projectile.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using Godot;
|
||||||
|
|
||||||
|
public partial class Projectile : Node3D
|
||||||
|
{
|
||||||
|
[Export]
|
||||||
|
public double Cooldown { get; protected set; }
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
private float _projectileSpeed = 100f;
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
Speed = _projectileSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float Speed { get; private set; }
|
||||||
|
|
||||||
|
public void OnTimeToLiveTimeout()
|
||||||
|
{
|
||||||
|
QueueFree();
|
||||||
|
}
|
||||||
|
}
|
||||||
10
Scripts/TestBullet.cs
Normal file
10
Scripts/TestBullet.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using Godot;
|
||||||
|
|
||||||
|
public partial class TestBullet : Projectile
|
||||||
|
{
|
||||||
|
public override void _PhysicsProcess(double delta)
|
||||||
|
{
|
||||||
|
Translate(new Vector3(0, 0, Speed * -(float)delta));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,32 +1,46 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using System;
|
|
||||||
|
|
||||||
public partial class TestCharacter : CharacterBody3D
|
public partial class TestCharacter : CharacterBody3D
|
||||||
{
|
{
|
||||||
[Export]
|
[Export]
|
||||||
private float _speed = 5.0f;
|
private float _speed = 5.0f;
|
||||||
|
[Export]
|
||||||
|
private PackedScene _attackPattern;
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
Vector3 velocity = Velocity;
|
if (Input.IsActionJustPressed("p1_fire"))
|
||||||
|
Fire();
|
||||||
|
|
||||||
// Get the input direction and handle the movement/deceleration.
|
Velocity = CalculateCharacterMovement();
|
||||||
// As good practice, you should replace UI actions with custom gameplay actions.
|
MoveAndSlide();
|
||||||
Vector2 inputDir = Input.GetVector("p1_left", "p1_right", "p1_up", "p1_down");
|
}
|
||||||
Vector3 direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized();
|
|
||||||
|
private Vector3 CalculateCharacterMovement()
|
||||||
|
{
|
||||||
|
var velocity = Velocity;
|
||||||
|
var inputDir = Input.GetVector("p1_left", "p1_right", "p1_up", "p1_down");
|
||||||
|
var direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized();
|
||||||
if (direction != Vector3.Zero)
|
if (direction != Vector3.Zero)
|
||||||
{
|
{
|
||||||
velocity.X = direction.X * _speed;
|
velocity.X = direction.X * _speed;
|
||||||
velocity.Z = direction.Z * _speed;
|
velocity.Z = direction.Z * _speed;
|
||||||
GetNode<Node3D>("Pivot").LookAt(Position + direction, Vector3.Up);
|
GetNode<Node3D>("Pivot").LookAt(Position + -direction, Vector3.Up);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
velocity.X = Mathf.MoveToward(Velocity.X, 0, _speed);
|
velocity.X = Mathf.MoveToward(Velocity.X, 0, _speed);
|
||||||
velocity.Z = Mathf.MoveToward(Velocity.Z, 0, _speed);
|
velocity.Z = Mathf.MoveToward(Velocity.Z, 0, _speed);
|
||||||
}
|
}
|
||||||
|
return velocity;
|
||||||
|
}
|
||||||
|
|
||||||
Velocity = velocity;
|
private async void Fire()
|
||||||
MoveAndSlide();
|
{
|
||||||
|
GD.Print("Shoot");
|
||||||
|
var projectile = _attackPattern.Instantiate<Projectile>();
|
||||||
|
projectile.Position = Position + new Vector3(0f, 0f, -0.2f);
|
||||||
|
GetParent().AddChild(projectile);
|
||||||
|
await ToSignal(GetTree().CreateTimer(projectile.Cooldown), "timeout");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,3 +40,17 @@ p1_down={
|
|||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null)
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
p1_fire={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
p1_altfire={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":2,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
[physics]
|
||||||
|
|
||||||
|
common/physics_ticks_per_second=144
|
||||||
|
|||||||
Reference in New Issue
Block a user