Skip to content

Commit

Permalink
You can no longer shoot while not aiming. Bullets now hit stuff very …
Browse files Browse the repository at this point in the history
…cool
  • Loading branch information
FredTheNoob committed Mar 16, 2021
1 parent 9e351e2 commit c12282f
Show file tree
Hide file tree
Showing 6 changed files with 277 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Assets/Assets/Sprites/crosshair.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
140 changes: 140 additions & 0 deletions Assets/Assets/Sprites/crosshair.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 112 additions & 2 deletions Assets/Scenes/Game World.unity
Original file line number Diff line number Diff line change
Expand Up @@ -62922,6 +62922,63 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 577719250}
m_PrefabAsset: {fileID: 0}
--- !u!1 &591064510
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 591064511}
- component: {fileID: 591064512}
m_Layer: 0
m_Name: EnterBuilding
m_TagString: EnterBuilding
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &591064511
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 591064510}
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: 2127199076}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!61 &591064512
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 591064510}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: -0.08463494}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0}
oldSize: {x: 1, y: 0.86875}
newSize: {x: 1, y: 0.86875}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 0.33945137, y: 0.18460037}
m_EdgeRadius: 0
--- !u!1 &671811589
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -332418,7 +332475,8 @@ SpriteRenderer:
m_SortingLayerID: -171121271
m_SortingLayer: 3
m_SortingOrder: 1
m_Sprite: {fileID: 21300000, guid: b719d256d7ff4e9428c97c4314850f15, type: 3}
m_Sprite: {fileID: -6142374563283994760, guid: 06caf4f95a1ebe04cb19a482498193a9,
type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
Expand Down Expand Up @@ -343072,6 +343130,57 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 1363577416}
m_PrefabAsset: {fileID: 0}
--- !u!1 &2033664850
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2033664852}
- component: {fileID: 2033664851}
m_Layer: 0
m_Name: AudioManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &2033664851
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2033664850}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a068a96cfaaf5614b9d9351f6e3c7dc1, type: 3}
m_Name:
m_EditorClassIdentifier:
sounds:
- name: Music
clip: {fileID: 8300000, guid: ddf347cd81e76df4888ad164d1f5d930, type: 3}
volume: 0.3
pitch: 1
spatialBlend: 0
source: {fileID: 0}
loop: 1
--- !u!4 &2033664852
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2033664850}
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: 0}
m_RootOrder: 11
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &2036242525
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -343725,5 +343834,6 @@ PrefabInstance:
propertyPath: m_Name
value: 160x160 Saloon_0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedComponents:
- {fileID: 8960931741605356859, guid: 62f95086422894f408bfb2d4a8530659, type: 3}
m_SourcePrefab: {fileID: 100100000, guid: 62f95086422894f408bfb2d4a8530659, type: 3}
6 changes: 3 additions & 3 deletions Assets/Scripts/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ private void ControllerShoot(InputAction.CallbackContext obj)
if (Time.time >= nextShootTime)
{
Vector2 controllerDir = playerInput.Player.Aim.ReadValue<Vector2>();
if (controllerDir == new Vector2(0,0)) controllerDir = new Vector2(1,0);
if (controllerDir == new Vector2(0,0)) return;

GameObject g = Instantiate(bulletPrefab, firePoint.position, Quaternion.identity);
g.GetComponent<Bullet>().MoveBullet(controllerDir.normalized);

nextShootTime = Time.time + 1f / shootRate;
}
}
Expand Down Expand Up @@ -98,7 +98,7 @@ void FixedUpdate()
Vector2 moveInput = playerInput.Player.Movement.ReadValue<Vector2>();
rb.velocity = moveInput * speed;

Vector2 aimInput = playerInput.Player.Aim.ReadValue<Vector2>();
Vector2 aimInput = playerInput.Player.Aim.ReadValue<Vector2>().normalized;
if (aimInput != new Vector2(0,0)) {
aimAssist.SetActive(true);
aimAssist.transform.localPosition = aimInput * new Vector2(5f,5f) + new Vector2(0,2.5f);
Expand Down
18 changes: 18 additions & 0 deletions Assets/Scripts/WeaponBehaviour/Bullet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,26 @@ public class Bullet : MonoBehaviour
public float speed = 20f;
public Rigidbody2D rb;

private void Start() {
Destroy(this, 3f);
}

public void MoveBullet(Vector3 pos)
{
rb.velocity = pos * speed;
}

private void OnTriggerEnter2D(Collider2D other)
{
if (!other.CompareTag("EnterBuilding"))
{
if (!other.CompareTag("NPC"))
{
rb.constraints = RigidbodyConstraints2D.FreezeAll;
this.GetComponent<SpriteRenderer>().enabled = false;
Destroy(this, 1f);
}
}

}
}
1 change: 1 addition & 0 deletions ProjectSettings/TagManager.asset
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ TagManager:
tags:
- Saloon
- NPC
- EnterBuilding
layers:
- Default
- TransparentFX
Expand Down

0 comments on commit c12282f

Please sign in to comment.