Add Grenade Launcher

This commit is contained in:
Sofia 2019-08-18 21:46:22 +03:00
parent 163e09d58a
commit bcac587806
14 changed files with 5439 additions and 15 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

View File

@ -0,0 +1,115 @@
fileFormatVersion: 2
guid: ea4d52c206902f547bc919613877b82a
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 10
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 0
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: -1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 32
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

@ -0,0 +1,11 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!62 &6200000
PhysicsMaterial2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: GrenadeMaterial
friction: 0.4
bounciness: 0.8

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2ae4d5024326a7145b2f3091d4bddd78
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 6200000
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: a405a747bdaeb9f48a1255e9948d26b6
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,262 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &3306765774511797525
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1528725660408968915}
m_Layer: 11
m_Name: Bobbing
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1528725660408968915
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3306765774511797525}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4462327695001662283}
- {fileID: 427857587156450783}
m_Father: {fileID: 4462327694118370271}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &4462327694118370270
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4462327694118370271}
- component: {fileID: 1737862779447396268}
- component: {fileID: 4462327694118370268}
- component: {fileID: 4462327694118370269}
- component: {fileID: 3522608540502111974}
m_Layer: 11
m_Name: Grenade Launcher
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4462327694118370271
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4462327694118370270}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1528725660408968915}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!50 &1737862779447396268
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4462327694118370270}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 0.4
m_LinearDrag: 5
m_AngularDrag: 12
m_GravityScale: 0
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 4
--- !u!61 &4462327694118370268
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4462327694118370270}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0}
oldSize: {x: 0, y: 0}
newSize: {x: 0, y: 0}
adaptiveTilingThreshold: 0
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
--- !u!114 &4462327694118370269
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4462327694118370270}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c80190f5b43dadf47ae89f04f092d1ff, type: 3}
m_Name:
m_EditorClassIdentifier:
Bullet: {fileID: 4482402865533696887, guid: a405a747bdaeb9f48a1255e9948d26b6, type: 3}
Sprite: {fileID: 4462327695001662280}
BulletHole: {fileID: 427857587156450783}
MaxCooldown: 0.4
MinCooldown: 0.4
Bobbing: {fileID: 3522608540502111974}
--- !u!114 &3522608540502111974
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4462327694118370270}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e796ba4c6f7efc449a10ed13ee42e34f, type: 3}
m_Name:
m_EditorClassIdentifier:
BobbedTransform: {fileID: 1528725660408968915}
BobbingMultiplier: 1
BobbingGravity: 0.07
BobbingLaunchSpeed: 0.05
BobbingFrequency: 0
BobbingDirection: {x: 0, y: 1}
--- !u!1 &4462327695001662282
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4462327695001662283}
- component: {fileID: 4462327695001662280}
m_Layer: 11
m_Name: Sprite
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4462327695001662283
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4462327695001662282}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1528725660408968915}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &4462327695001662280
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4462327695001662282}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: -947994997
m_SortingLayer: 4
m_SortingOrder: 1
m_Sprite: {fileID: 21300000, guid: a7290ef708bb1064fbe466f56eb95ac6, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!1 &5364776498526555370
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 427857587156450783}
m_Layer: 11
m_Name: BulletHole
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &427857587156450783
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5364776498526555370}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0.389, y: 0.129, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1528725660408968915}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: da2dfe8e5a4e5f64597d1fa9fcecce7e
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -29,5 +29,20 @@ namespace Saltosion.OneWeapon.Guns {
Collider.attachedRigidbody.AddForce(Direction * 4 * Intensity, ForceMode2D.Impulse);
}
}
public void DoDamageAOE(float Damage, float Radius, float Intensity) {
Collider2D[] NearbyColliders = Physics2D.OverlapCircleAll(transform.position, Radius);
foreach (Collider2D curr in NearbyColliders) {
Vector2 Delta = (curr.transform.position - transform.position);
Vector2 Dir = Delta.normalized;
float ScaledDistance = 1 - Mathf.Clamp((Delta.magnitude - (Radius / 3)) / (Radius - (Radius / 3)), 0, 1);
this.DoDamage(ScaledDistance * Damage, ScaledDistance * Intensity, curr, Dir);
if (curr.attachedRigidbody != null && curr.attachedRigidbody.bodyType == RigidbodyType2D.Dynamic) {
// FIXME: AcceleratedMovement currently overrides Rigidbody.velocity so this doesn't do anything
curr.attachedRigidbody.AddForce(Dir * 10f, ForceMode2D.Impulse);
}
}
}
}
}

View File

@ -0,0 +1,52 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Saltosion.OneWeapon.Guns {
[RequireComponent(typeof(Bullet))]
public class Grenade : MonoBehaviour {
private Bullet Bullet;
[Header("Children")]
public Rigidbody2D Body;
public ParticleSystem Explosion;
public SpriteRenderer Sprite;
[Header("Values")]
public float ShootForce = 8;
public float Torque = 5;
public float Lifetime = 1;
public float ExplodeRadius = 3;
void Start() {
Bullet = GetComponent<Bullet>();
Body = GetComponent<Rigidbody2D>();
Body.SetRotation(Bullet.InitialRotation);
Body.AddForce(Bullet.Direction.normalized * ShootForce, ForceMode2D.Impulse);
Body.AddTorque(Random.value * Torque - Torque / 2);
Explosion.Stop();
}
void Update() {
Lifetime -= Time.deltaTime;
if (Lifetime < 0 && !Bullet.HasExploded) {
Explosion.Play();
Bullet.HasExploded = true;
Destroy(Body);
Destroy(Sprite);
Bullet.DoDamageAOE(18, ExplodeRadius, 1.5f);
}
if (Lifetime < -1) {
Destroy(gameObject);
}
}
private void OnDrawGizmosSelected() {
Gizmos.color = new Color(1.0f, 0.2f, 0.2f, 0.8f);
Gizmos.DrawWireSphere(transform.position, ExplodeRadius);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 271009875a8162a44bd5d4a4af90653d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -56,21 +56,7 @@ namespace Saltosion.OneWeapon.Guns {
Trail.Stop();
DeathTimer = 19;
Collider2D[] NearbyColliders = Physics2D.OverlapCircleAll(transform.position, ExplodeRadius);
foreach (Collider2D curr in NearbyColliders) {
Vector2 Delta = (curr.transform.position - transform.position);
Vector2 Dir = Delta.normalized;
float ScaledDistance = 1 - Mathf.Clamp((Delta.magnitude - (ExplodeRadius / 3)) / (ExplodeRadius - (ExplodeRadius / 3)), 0, 1);
Bullet.DoDamage(ScaledDistance * 20, ScaledDistance * 2, curr, Dir);
if (curr.attachedRigidbody != null && curr.attachedRigidbody.bodyType == RigidbodyType2D.Dynamic) {
// FIXME: AcceleratedMovement currently overrides Rigidbody.velocity so this doesn't do anything
curr.attachedRigidbody.AddForce(Dir * 10f, ForceMode2D.Impulse);
}
}
// Do damage here, kill everyone
Bullet.DoDamageAOE(20, ExplodeRadius, 2);
}
private void OnDrawGizmosSelected() {

BIN
Raw Assets/Grenade.xcf Normal file

Binary file not shown.