Skip to content

Commit

Permalink
Complite chapter 11.3
Browse files Browse the repository at this point in the history
  • Loading branch information
DaikonNimono committed Mar 15, 2024
1 parent e7ed9e1 commit 0d0e178
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 21 deletions.
50 changes: 50 additions & 0 deletions data/csharp_template/FP_controller/components/VFXController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Unigine;
#region Math Variables
#if UNIGINE_DOUBLE
using Vec3 = Unigine.dvec3;
using Mat4 = Unigine.dmat4;
#else
using Vec3 = Unigine.vec3;
using Mat4 = Unigine.mat4;
#endif
#endregion

[Component(PropertyGuid = "19c5bafbe8a7932cdd4890d4a298a355b4d1dec7")]
public class VFXController : Component
{
// NodeReference для эффектов вспышки выстрела и попадания
[ParameterFile(Filter = ".node")]
public string hitPrefab = null;

[ParameterFile(Filter = ".node")]
public string muzzleFlashPrefab = null;

public void OnShoot(Mat4 transform)
{
// если не задан NodeReference эффекта вспышки, ничего не делаем
if (string.IsNullOrEmpty(muzzleFlashPrefab))
return;

// загружаем NodeReference эффекта выстрела
Node muzzleFlashVFX = World.LoadNode(muzzleFlashPrefab);
// устанавливаем положение вспышки на указанные координаты дула пистолета
muzzleFlashVFX.WorldTransform = transform;
}

public void OnHit(Vec3 hitPoint, vec3 hitNormal, Unigine.Object hitObject)
{
// если нода эффекта попадания не указана ничего не делаем
if (string.IsNullOrEmpty(hitPrefab))
return;

// загружаем ноду эффекта попадания из файла
Node hitVFX = World.LoadNode(hitPrefab);
// устанавливаем загруженную ноду в указанную точку попадания и разворачиваем ее в направлении вектора нормали
hitVFX.Parent = hitObject;
hitVFX.WorldPosition = hitPoint;
hitVFX.SetWorldDirection(hitNormal, vec3.UP, MathLib.AXIS.Y);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<asset version="2.18.0.1">
<guid>b23baaa53cabf948b0118226ccc00803ae73be91</guid>
<type>component</type>
<hash>faabea7a</hash>
<runtimes>
<runtime id="b23baaa53cabf948b0118226ccc00803ae73be91" name="VFXController.cs" link="0"/>
<runtime id="19c5bafbe8a7932cdd4890d4a298a355b4d1dec7" name="VFXController.prop" link="1" type="4"/>
</runtimes>
</asset>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class WeaponController : Component
public PlayerDummy shootingCamera = null;
public ShootInput shootInput = null;
public NodeDummy weaponMuzzle = null;
public VFXController vfx = null;

public int damage = 1;

// маска Intersection чтобы определить, в какие объекты могут попадать пули
Expand All @@ -25,6 +27,10 @@ public class WeaponController : Component

public void Shoot()
{
// визуализируем эффект выстрела
if (weaponMuzzle)
vfx.OnShoot(weaponMuzzle.WorldTransform);

// задаем начало отрезка (p0) в позиции камеры и конец (p1) - в точке удаленной на 100 единиц в направлении взгляда камеры
Vec3 p0 = shootingCamera.WorldPosition;
Vec3 p1 = shootingCamera.WorldPosition + shootingCamera.GetWorldDirection() * 100;
Expand All @@ -39,6 +45,9 @@ public void Shoot()
{
// отрисовываем нормаль к поверхности в точке попадания при помощи Visualizer
Visualizer.RenderVector(hitInfo.Point, hitInfo.Point + hitInfo.Normal, vec4.RED, 0.25f, false, 2.0f);

// визуализируем эффект попадания в точке пересечения
vfx.OnHit(hitInfo.Point, hitInfo.Normal, hitObject);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<asset version="2.18.0.1">
<guid>1005e2b9f814eb840a73c08a2aabf58cc6fbbb65</guid>
<type>component</type>
<hash>bc2743d2</hash>
<hash>fbeaac5a</hash>
<runtimes>
<runtime id="1005e2b9f814eb840a73c08a2aabf58cc6fbbb65" name="WeaponController.cs" link="0"/>
<runtime id="f242c1ef0b63af70a079e9989c2f5f4b62a1c57b" name="WeaponController.prop" link="1" type="4"/>
Expand Down
49 changes: 29 additions & 20 deletions data/csharp_template/FP_controller/first_person_controller.node
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<nodes version="2.18.0.1">
<node type="ObjectDummy" id="1893352644" trigger_interaction_enabled="1" name="player">
<body type="BodyDummy" id="1290189223" frozen="0">
<shape type="ShapeCapsule" id="1119263865" transform="0.99999994 0 0 0 0 1 0 0 0 0 0.999999762 0 0 0 0.875 1">
<node type="ObjectDummy" id="140775476" trigger_interaction_enabled="1" name="player">
<body type="BodyDummy" id="735835149" frozen="0">
<shape type="ShapeCapsule" id="488064195" transform="0.99999994 0 0 0 0 1 0 0 0 0 0.999999762 0 0 0 0.875 1">
<radius>0.300000012</radius>
<height>1.14999998</height>
</shape>
</body>
<properties>
<property parent="7abd3d1dd6399bd8498bed57e699aacada031ba1" guid="72e8187ba757e6a0925e6b36683deed042fd4ec2">
<property parent="7abd3d1dd6399bd8498bed57e699aacada031ba1" guid="b297453b8de550ff14b6a0f63ded9bb418145082">
<parameter name="useObjectBody">1</parameter>
<parameter name="cameraMode">2</parameter>
<parameter name="camera">638486867</parameter>
<parameter name="camera">487357955</parameter>
<parameter name="nearClipping">0.100000001</parameter>
<parameter name="farClipping">100000</parameter>
</property>
<property parent="19086705f07c9e76dd45800696a0f47c5ef21cf1" guid="f79e2bcd3e19d7eb11efd3ee686ef0ae419f3f39"/>
<property parent="f242c1ef0b63af70a079e9989c2f5f4b62a1c57b" guid="1a38d425d704e1555040ef5824f30aca3146df44">
<parameter name="shootingCamera">638486867</parameter>
<parameter name="shootInput">f79e2bcd3e19d7eb11efd3ee686ef0ae419f3f39</parameter>
<property parent="19086705f07c9e76dd45800696a0f47c5ef21cf1" guid="ec89de8d1e59999f36adf1ae9899d4026a3cd5f9"/>
<property parent="f242c1ef0b63af70a079e9989c2f5f4b62a1c57b" guid="31264ee5f3bda396551c9b189e414fedc4180704">
<parameter name="shootingCamera">487357955</parameter>
<parameter name="shootInput">ec89de8d1e59999f36adf1ae9899d4026a3cd5f9</parameter>
<parameter name="weaponMuzzle">1015006385</parameter>
<parameter name="vfx">8357b487d100d039838ffa90a2e7dc4073d6e693</parameter>
<parameter name="mask">0xffffffff</parameter>
</property>
<property parent="19c5bafbe8a7932cdd4890d4a298a355b4d1dec7" guid="8357b487d100d039838ffa90a2e7dc4073d6e693">
<parameter name="hitPrefab">guid://8c628a2a1e96b3815d3476ec7c87055be14f7afe</parameter>
<parameter name="muzzleFlashPrefab">guid://dda131848d3d0f13356549567731f0bdb2587af8</parameter>
</property>
</properties>
<transform>1 -2.0605739e-13 0 0.0 0 0.99999994 0 0.0 0 0 0.99999994 0.0 0 0 0 1.0</transform>
<node type="PlayerDummy" id="638486867" name="PlayerDummy">
<transform>1 -2.4868996e-13 0 0.0 0 0.99999994 0 0.0 0 0 0.99999994 0.0 0 0 0 1.0</transform>
<node type="PlayerDummy" id="487357955" name="PlayerDummy">
<fov>75</fov>
<zfar>100000</zfar>
<oblique_frustum_plane>0 0 -1 0</oblique_frustum_plane>
Expand All @@ -32,19 +38,19 @@
<is_listener>1</is_listener>
<controlled>1</controlled>
<transform>1 -3.7421756e-14 0 0.0 0 5.9604638e-08 0.99999982 0.0 -3.742176e-14 -1 5.9604652e-08 0.0 0 0 1.65 1.0</transform>
<node type="NodeDummy" id="1593704086" name="hands">
<node type="NodeDummy" id="2123467654" name="hands">
<transform>1.0000001 0 0 0.0 0 5.9604645e-08 -0.99999994 0.0 0 1.0000004 5.9604673e-08 0.0 0 0 0 1.0</transform>
<node type="ObjectMeshSkinned" id="527082749" name="hands">
<node type="ObjectMeshSkinned" id="1199598893" name="hands">
<mesh_name>guid://60020a35ebc7961062ebf22feb7ff9c29363ee39</mesh_name>
<fps_visible_camera>-1</fps_visible_camera>
<fps_visible_shadow>30</fps_visible_shadow>
<fps_invisible>0</fps_invisible>
<speed>30</speed>
<surface name="hands_mat" intersection="1" shadow_mask="0x0" material="6b953d4d25f4be4842b54d076203a6baf33686d1"/>
<properties>
<property parent="f21127b33f4bf8120d79170e808b628f1d16ea1a" guid="b7c643c7750f0e103a2c26d053e10006c7a161d3">
<parameter name="fpsController">72e8187ba757e6a0925e6b36683deed042fd4ec2</parameter>
<parameter name="shootInput">f79e2bcd3e19d7eb11efd3ee686ef0ae419f3f39</parameter>
<property parent="f21127b33f4bf8120d79170e808b628f1d16ea1a" guid="1ad3fc9f3856d09ab6f43e0ab020e10242923ad6">
<parameter name="fpsController">b297453b8de550ff14b6a0f63ded9bb418145082</parameter>
<parameter name="shootInput">ec89de8d1e59999f36adf1ae9899d4026a3cd5f9</parameter>
<parameter name="idleAnimation">guid://e61be599754592242eb5b733e6a292f613446ddd</parameter>
<parameter name="moveForwardAnimation">guid://5b9eff0f2598e1220b37ee19579500a41d4553b3</parameter>
<parameter name="moveBackwardAnimation">guid://0618cf62aee4875963a848e477497ef3f97a37b6</parameter>
Expand All @@ -54,24 +60,27 @@
</property>
</properties>
<transform>1 1.6689304e-06 4.0911085e-14 0.0 -1.6689298e-06 1 2.4335923e-08 0.0 -2.9612317e-16 -2.4335897e-08 0.99999988 0.0 5.4846364e-21 0.25 -0.02499938 1.0</transform>
<node type="WorldTransformBone" id="1867194936" name="WorldTransformBone">
<node type="WorldTransformBone" id="853109928" name="WorldTransformBone">
<bone>joint_hold</bone>
<transform>0.17363977 0.25486851 0.95125794 0.0 -4.068017e-06 0.96593118 -0.2587992 0.0 -0.9848094 0.044934005 0.16772509 0.0 0.17025253 0.16304654 -0.028451072 1.0</transform>
<node type="NodeDummy" id="710541367" name="pistol">
<node type="NodeDummy" id="254568423" name="pistol">
<transform>0.99999988 0 0 0.0 0 1.0000004 0 0.0 0 0 1 0.0 0 0 0 1.0</transform>
<node type="ObjectMeshSkinned" id="1148575786" name="pistol">
<node type="ObjectMeshSkinned" id="1487225882" name="pistol">
<mesh_name>guid://2a8475f4b0fc28c3ac85b7462c1525ed9ac34e68</mesh_name>
<fps_visible_camera>-1</fps_visible_camera>
<fps_visible_shadow>30</fps_visible_shadow>
<fps_invisible>0</fps_invisible>
<speed>30</speed>
<surface name="pistol_mat" intersection="1" shadow_mask="0x0" material="0632ab51782cec7c550c5daba114d70eb88b7315"/>
<transform>1 -5.8887914e-25 2.9611872e-16 0.0 -3.8976016e-24 1 2.4335929e-08 0.0 -2.9611872e-16 -2.4335929e-08 1 0.0 0 0 0 1.0</transform>
<node type="NodeDummy" id="1015006385" name="muzzle">
<transform>0.99999982 -2.9802322e-08 1.1920929e-07 0.0 1.1920929e-07 1.0000008 8.9406967e-08 0.0 -1.4901161e-08 -1.3783574e-07 0.99999982 0.0 0.0040171146 0.28044361 0.084044278 1.0</transform>
</node>
</node>
</node>
</node>
</node>
<node type="ObjectMeshStatic" id="299241857" name="player_hit_box">
<node type="ObjectMeshStatic" id="1821603420" name="player_hit_box">
<streaming_mode_vram>0</streaming_mode_vram>
<streaming_mode_ram>0</streaming_mode_ram>
<mesh_name>guid://89640b0d7ffa9f7f02a1a97753abc138ef6e3f24</mesh_name>
Expand Down
2 changes: 2 additions & 0 deletions data/guids.db
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@
"fe7e107fcadf21ef96ab03e986da74a12658a17c": "csharp_template/template_render_settings/template_virtual_reality.render.meta",
"ea9d2d9f8f3d2a3b4d2c360902b89a2e21bcd11c": "configs/default.user.meta",
"cb3839fe5ac15e0145621fbc772e1e9caa5a4247": "fps/components/Lifetime.cs.meta",
"b27eae5f554475bb72d78fc8446f0ebec0ed12eb": "csharp_template/FP_controller/components/VFXController.cs.meta",
"117116973d68f9d5d633e5a255fb6f67627b61ee": "csharp_template/FP_controller/components/HandAnimationController.cs.meta",
"1e9d3c93b8b196fb5847ecccb5871f542bef2adf": "csharp_template/FP_controller/components/WeaponController.cs.meta",
"cd808aa08f142fcaf8300c9eea1d61eaa8c28057": "csharp_template/FP_controller/components/FirstPersonController.cs.meta",
Expand Down Expand Up @@ -2045,6 +2046,7 @@
"0c8e43c90ace7f55fc25e143ee2cb296e8fb540e": "configs/default.user",
"31882be4a9adaffa787a3342ade773c4defe75cb": "editor2/resources/template_graphs/material_graph_decal_water",
"4aed6f037c03c8869f9b862d692fb1a8ee0be8e7": "fps/components/Lifetime.cs",
"b23baaa53cabf948b0118226ccc00803ae73be91": "csharp_template/FP_controller/components/VFXController.cs",
"4e28861d843434e837504ef0429bf99b43420c5c": "csharp_template/FP_controller/components/HandAnimationController.cs",
"1005e2b9f814eb840a73c08a2aabf58cc6fbbb65": "csharp_template/FP_controller/components/WeaponController.cs",
"5fc06ee29974a0d934a294642d945473e5d80f36": "csharp_template/FP_controller/components/FirstPersonController.cs",
Expand Down

0 comments on commit 0d0e178

Please sign in to comment.