Add shooting rays and crosshair

This commit is contained in:
Jens Pitkänen 2020-08-08 06:20:23 +03:00
parent 7d60350142
commit 07720ef5e6
7 changed files with 132 additions and 29 deletions

View File

@ -133,12 +133,12 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6870369192359082222} m_GameObject: {fileID: 6870369192359082222}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 1.62, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 4112688413114993738} - {fileID: 4112688413114993738}
m_Father: {fileID: 1618967478166023428} m_Father: {fileID: 3742571491028069048}
m_RootOrder: 3 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!20 &4414509310837669210 --- !u!20 &4414509310837669210
Camera: Camera:
@ -235,7 +235,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: f6e08271c272323469510daa22c35599, type: 3} m_Script: {fileID: 11500000, guid: f6e08271c272323469510daa22c35599, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
Camera: {fileID: 9173392441446035453} Camera: {fileID: 3742571491028069048}
DisableInput: 0 DisableInput: 0
FullSyncFrequency: 2 FullSyncFrequency: 2
--- !u!114 &3508289943927587728 --- !u!114 &3508289943927587728
@ -275,6 +275,10 @@ PrefabInstance:
propertyPath: m_Layer propertyPath: m_Layer
value: 11 value: 11
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4833458671639168932, guid: 0bffd92c46c257840806f5e957954800, type: 3}
propertyPath: m_RootOrder
value: 3
objectReference: {fileID: 0}
- target: {fileID: 7391558911651855222, guid: 0bffd92c46c257840806f5e957954800, type: 3} - target: {fileID: 7391558911651855222, guid: 0bffd92c46c257840806f5e957954800, type: 3}
propertyPath: m_Layer propertyPath: m_Layer
value: 10 value: 10
@ -330,13 +334,13 @@ GameObject:
m_CorrespondingSourceObject: {fileID: 7391558912774766599, guid: 0bffd92c46c257840806f5e957954800, type: 3} m_CorrespondingSourceObject: {fileID: 7391558912774766599, guid: 0bffd92c46c257840806f5e957954800, type: 3}
m_PrefabInstance: {fileID: 8134536652936637724} m_PrefabInstance: {fileID: 8134536652936637724}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!4 &1618967478166023428 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 7391558912774766616, guid: 0bffd92c46c257840806f5e957954800, type: 3}
m_PrefabInstance: {fileID: 8134536652936637724}
m_PrefabAsset: {fileID: 0}
--- !u!1 &7808238467771803924 stripped --- !u!1 &7808238467771803924 stripped
GameObject: GameObject:
m_CorrespondingSourceObject: {fileID: 2071588178488902664, guid: 0bffd92c46c257840806f5e957954800, type: 3} m_CorrespondingSourceObject: {fileID: 2071588178488902664, guid: 0bffd92c46c257840806f5e957954800, type: 3}
m_PrefabInstance: {fileID: 8134536652936637724} m_PrefabInstance: {fileID: 8134536652936637724}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!4 &3742571491028069048 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 4833458671639168932, guid: 0bffd92c46c257840806f5e957954800, type: 3}
m_PrefabInstance: {fileID: 8134536652936637724}
m_PrefabAsset: {fileID: 0}

View File

@ -1,5 +1,35 @@
%YAML 1.1 %YAML 1.1
%TAG !u! tag:unity3d.com,2011: %TAG !u! tag:unity3d.com,2011:
--- !u!1 &379718841342258282
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2637233632139837434}
m_Layer: 0
m_Name: GunShootPoint
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2637233632139837434
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 379718841342258282}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0.05, z: 0.55}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 8204020546429986303}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1536982187247873486 --- !u!1 &1536982187247873486
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -31,6 +61,7 @@ Transform:
- {fileID: 7485469696879136409} - {fileID: 7485469696879136409}
- {fileID: 7297658690187546150} - {fileID: 7297658690187546150}
- {fileID: 1308935639964380857} - {fileID: 1308935639964380857}
- {fileID: 2637233632139837434}
m_Father: {fileID: 1865991757674780053} m_Father: {fileID: 1865991757674780053}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -522,7 +553,7 @@ BoxCollider:
m_IsTrigger: 0 m_IsTrigger: 0
m_Enabled: 1 m_Enabled: 1
serializedVersion: 2 serializedVersion: 2
m_Size: {x: 0.5, y: 1.3, z: 0.5} m_Size: {x: 0.7, y: 1.3, z: 0.7}
m_Center: {x: 0, y: 0.65, z: 0} m_Center: {x: 0, y: 0.65, z: 0}
--- !u!1 &7391558912774766599 --- !u!1 &7391558912774766599
GameObject: GameObject:
@ -557,6 +588,7 @@ Transform:
- {fileID: 7391558912582364399} - {fileID: 7391558912582364399}
- {fileID: 7391558913662534769} - {fileID: 7391558913662534769}
- {fileID: 7391558912167870012} - {fileID: 7391558912167870012}
- {fileID: 4833458671639168932}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -616,6 +648,11 @@ MonoBehaviour:
Body: {fileID: 7391558913662534769} Body: {fileID: 7391558913662534769}
Gun: {fileID: 1865991757674780053} Gun: {fileID: 1865991757674780053}
GunBobber: {fileID: 2075495528035690810} GunBobber: {fileID: 2075495528035690810}
CameraRoot: {fileID: 4833458671639168932}
BulletSourcePoint: {fileID: 2637233632139837434}
BulletHitLayer:
serializedVersion: 2
m_Bits: 512
Lerpables: Lerpables:
- {fileID: 2566772175078312154} - {fileID: 2566772175078312154}
- {fileID: 1798037817325599949} - {fileID: 1798037817325599949}
@ -678,7 +715,7 @@ BoxCollider:
m_IsTrigger: 0 m_IsTrigger: 0
m_Enabled: 1 m_Enabled: 1
serializedVersion: 2 serializedVersion: 2
m_Size: {x: 0.5, y: 0.5, z: 0.5} m_Size: {x: 0.7, y: 0.7, z: 0.7}
m_Center: {x: 0, y: 0, z: 0} m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &7391558913662534768 --- !u!1 &7391558913662534768
GameObject: GameObject:
@ -870,6 +907,36 @@ BoxCollider:
serializedVersion: 2 serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1} m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0} m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &8506552293636427135
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4833458671639168932}
m_Layer: 0
m_Name: CameraRoot
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4833458671639168932
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8506552293636427135}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1.6, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 7391558912774766616}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &8952758565847848432 --- !u!1 &8952758565847848432
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -1365,7 +1365,7 @@ Mesh:
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: pb_Mesh16548 m_Name: pb_Mesh21336
serializedVersion: 10 serializedVersion: 10
m_SubMeshes: m_SubMeshes:
- serializedVersion: 2 - serializedVersion: 2
@ -3089,7 +3089,7 @@ Mesh:
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: pb_Mesh16484 m_Name: pb_Mesh21252
serializedVersion: 10 serializedVersion: 10
m_SubMeshes: m_SubMeshes:
- serializedVersion: 2 - serializedVersion: 2
@ -3789,7 +3789,7 @@ Mesh:
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: pb_Mesh16628 m_Name: pb_Mesh21446
serializedVersion: 10 serializedVersion: 10
m_SubMeshes: m_SubMeshes:
- serializedVersion: 2 - serializedVersion: 2
@ -4458,7 +4458,7 @@ Mesh:
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: pb_Mesh16328 m_Name: pb_Mesh21058
serializedVersion: 10 serializedVersion: 10
m_SubMeshes: m_SubMeshes:
- serializedVersion: 2 - serializedVersion: 2
@ -5792,7 +5792,7 @@ Mesh:
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: pb_Mesh16598 m_Name: pb_Mesh21416
serializedVersion: 10 serializedVersion: 10
m_SubMeshes: m_SubMeshes:
- serializedVersion: 2 - serializedVersion: 2
@ -7736,7 +7736,7 @@ Mesh:
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: pb_Mesh16694 m_Name: pb_Mesh21540
serializedVersion: 10 serializedVersion: 10
m_SubMeshes: m_SubMeshes:
- serializedVersion: 2 - serializedVersion: 2
@ -8414,7 +8414,7 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1618967478166023428, guid: e3d975a8d1b28eb4b9f646262c56653d, type: 3} - target: {fileID: 1618967478166023428, guid: e3d975a8d1b28eb4b9f646262c56653d, type: 3}
propertyPath: m_LocalPosition.y propertyPath: m_LocalPosition.y
value: 0 value: 0.02
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1618967478166023428, guid: e3d975a8d1b28eb4b9f646262c56653d, type: 3} - target: {fileID: 1618967478166023428, guid: e3d975a8d1b28eb4b9f646262c56653d, type: 3}
propertyPath: m_LocalPosition.z propertyPath: m_LocalPosition.z
@ -11237,7 +11237,7 @@ Mesh:
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: pb_Mesh16288 m_Name: pb_Mesh21000
serializedVersion: 10 serializedVersion: 10
m_SubMeshes: m_SubMeshes:
- serializedVersion: 2 - serializedVersion: 2
@ -12743,7 +12743,7 @@ Mesh:
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: pb_Mesh16528 m_Name: pb_Mesh21310
serializedVersion: 10 serializedVersion: 10
m_SubMeshes: m_SubMeshes:
- serializedVersion: 2 - serializedVersion: 2
@ -16507,7 +16507,7 @@ Mesh:
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: pb_Mesh16314 m_Name: pb_Mesh21036
serializedVersion: 10 serializedVersion: 10
m_SubMeshes: m_SubMeshes:
- serializedVersion: 2 - serializedVersion: 2
@ -16827,7 +16827,7 @@ Mesh:
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: pb_Mesh16576 m_Name: pb_Mesh21364
serializedVersion: 10 serializedVersion: 10
m_SubMeshes: m_SubMeshes:
- serializedVersion: 2 - serializedVersion: 2
@ -17294,7 +17294,7 @@ Mesh:
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: pb_Mesh16652 m_Name: pb_Mesh21478
serializedVersion: 10 serializedVersion: 10
m_SubMeshes: m_SubMeshes:
- serializedVersion: 2 - serializedVersion: 2
@ -17550,7 +17550,7 @@ Mesh:
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: pb_Mesh16664 m_Name: pb_Mesh21490
serializedVersion: 10 serializedVersion: 10
m_SubMeshes: m_SubMeshes:
- serializedVersion: 2 - serializedVersion: 2
@ -17888,7 +17888,7 @@ Mesh:
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: pb_Mesh16268 m_Name: pb_Mesh20978
serializedVersion: 10 serializedVersion: 10
m_SubMeshes: m_SubMeshes:
- serializedVersion: 2 - serializedVersion: 2
@ -18052,7 +18052,7 @@ Mesh:
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: pb_Mesh16434 m_Name: pb_Mesh21192
serializedVersion: 10 serializedVersion: 10
m_SubMeshes: m_SubMeshes:
- serializedVersion: 2 - serializedVersion: 2

View File

@ -49,8 +49,10 @@ namespace NeonTea.Quakeball.Players {
ShootAction = new InputAction("Shoot", binding: "<Mouse>/leftButton"); ShootAction = new InputAction("Shoot", binding: "<Mouse>/leftButton");
ShootAction.performed += _ => { ShootAction.performed += _ => {
ShootData shootData = new ShootData(Player.Pitch, Player.Yaw, Player.CreateSyncPacket()); if (Networking.Net.Singleton.Instance != null) {
Networking.Net.Singleton.Instance.LocalPlayerAction(PlayerAction.Shoot, shootData); ShootData shootData = new ShootData(Player.Pitch, Player.Yaw, Player.CreateSyncPacket());
Networking.Net.Singleton.Instance.LocalPlayerAction(PlayerAction.Shoot, shootData);
}
Player.Shoot(); Player.Shoot();
}; };

View File

@ -22,6 +22,12 @@ namespace NeonTea.Quakeball.Players {
public Transform Gun; public Transform Gun;
public Animator GunBobber; public Animator GunBobber;
[Header("Shooting")]
[Tooltip("For raycasting the shoot target.")]
public Transform CameraRoot;
public Transform BulletSourcePoint;
public LayerMask BulletHitLayer;
[Header("Visuals")] [Header("Visuals")]
public DesyncLerper[] Lerpables; public DesyncLerper[] Lerpables;
@ -135,7 +141,22 @@ namespace NeonTea.Quakeball.Players {
} }
public void Shoot() { public void Shoot() {
Terminal.Singleton.Println("<color=#F00><b>BANG!</b></color>"); Vector3 From = CameraRoot.position;
Vector3 Direction = CameraRoot.forward;
RaycastHit Hit;
if (Physics.Raycast(From, Direction, out Hit)) {
Vector3 To = Hit.point;
Vector3 GunPoint = BulletSourcePoint.position;
Vector3 Delta = To - GunPoint;
if (Physics.Raycast(GunPoint, Delta, out Hit, Delta.magnitude, BulletHitLayer)) {
Player Player = Hit.rigidbody.GetComponent<Player>();
if (Player != null) {
Debug.DrawLine(GunPoint, To, Color.red, 5f);
}
} else {
Debug.DrawLine(GunPoint, To, Color.yellow, 5f);
}
}
} }
public bool IsGrounded() { public bool IsGrounded() {

8
Assets/Sprites.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e9cb629d803014f48b2206b875c1f76c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1
CREDITS.md Normal file
View File

@ -0,0 +1 @@
- [Crosshair](Assets/Sprites/Crosshair.png) by MarkieAnn Packer from the Noun Project