Raycast in ShootController.cs
parent
8b04234a48
commit
3cc01482f6
@ -0,0 +1,6 @@
|
|||||||
|
<Project Sdk="Godot.NET.Sdk/4.2.0-dev.5">
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
@ -0,0 +1,34 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://bk5ovc0kwj1g2"
|
||||||
|
path="res://.godot/imported/icon-dark.png-2f929ad0cdeb04ca4efbb81b0e9c8312.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://graphics/icon-dark.png"
|
||||||
|
dest_files=["res://.godot/imported/icon-dark.png-2f929ad0cdeb04ca4efbb81b0e9c8312.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
@ -1,19 +1,35 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Godot.Collections;
|
||||||
|
|
||||||
namespace Evolution.scripts;
|
namespace Evolution.scripts;
|
||||||
|
|
||||||
public partial class ShootController : Node {
|
public partial class ShootController : Node {
|
||||||
[Export] private Node3D blaster;
|
[Export] private Node3D blaster;
|
||||||
[Export] private GpuParticles3D shootParticle;
|
[Export] private GpuParticles3D shootParticle;
|
||||||
|
[Export] private Camera3D camera;
|
||||||
public override void _Ready() => GD.Print($"{blaster}: {shootParticle}");
|
public override void _Ready() => GD.Print($"{blaster}: {shootParticle}");
|
||||||
|
|
||||||
public override void _Input(InputEvent @event) {
|
public override void _Input(InputEvent @event) {
|
||||||
if (@event is InputEventMouseButton eventMouseButton) {
|
switch (@event) {
|
||||||
|
case InputEventMouseButton eventMouseButton:
|
||||||
shootParticle.Emitting = eventMouseButton.Pressed;
|
shootParticle.Emitting = eventMouseButton.Pressed;
|
||||||
|
break;
|
||||||
|
case InputEventMouseMotion eventMouseMotion:
|
||||||
|
Vector2 mousePosition = eventMouseMotion.Position;
|
||||||
|
Vector3 raycastFrom = camera.ProjectRayOrigin(mousePosition);
|
||||||
|
Vector3 raycastTo = camera.ProjectRayNormal(mousePosition);
|
||||||
|
PhysicsDirectSpaceState3D spaceState = camera.GetWorld3D().DirectSpaceState;
|
||||||
|
PhysicsRayQueryParameters3D query = PhysicsRayQueryParameters3D.Create(raycastFrom, raycastTo);
|
||||||
|
Dictionary raycastResults = spaceState.IntersectRay(query);
|
||||||
|
foreach (KeyValuePair<Variant,Variant> raycastResult in raycastResults) {
|
||||||
|
if (raycastResult.Key.AsString() == "position") {
|
||||||
|
GD.Print($"raycastResult.Position = {raycastResult.Value}");
|
||||||
|
blaster.LookAt(raycastResults.FirstOrDefault().Value.AsVector3());
|
||||||
}
|
}
|
||||||
else if (@event is InputEventMouseMotion eventMouseMotion) {
|
}
|
||||||
blaster.LookAt(new(eventMouseMotion.Position.X, eventMouseMotion.Position.Y, 0));
|
break;
|
||||||
// blaster.RotateY(eventMouseMotion.GlobalPosition.Y);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue