From b8245f332a2f4ff282c94255fd18f54d42c0b1f1 Mon Sep 17 00:00:00 2001 From: Joshua Reason Date: Sat, 1 Feb 2020 18:13:03 +1100 Subject: [PATCH] Added add force --- Assets/Materials/Temp3.mat | 77 ++++++++++++++++++++++++ Assets/Materials/Temp3.mat.meta | 8 +++ Assets/Scripts/ExplosionTest.cs | 22 +++++++ Assets/Scripts/ExplosionTest.cs.meta | 11 ++++ Assets/Scripts/Input/PlayerController.cs | 7 +++ 5 files changed, 125 insertions(+) create mode 100644 Assets/Materials/Temp3.mat create mode 100644 Assets/Materials/Temp3.mat.meta create mode 100644 Assets/Scripts/ExplosionTest.cs create mode 100644 Assets/Scripts/ExplosionTest.cs.meta diff --git a/Assets/Materials/Temp3.mat b/Assets/Materials/Temp3.mat new file mode 100644 index 0000000..f7094fe --- /dev/null +++ b/Assets/Materials/Temp3.mat @@ -0,0 +1,77 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Temp3 + m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} + m_ShaderKeywords: + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + - _BumpScale: 1 + - _Cutoff: 0.5 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _GlossMapScale: 1 + - _Glossiness: 0.5 + - _GlossyReflections: 1 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _UVSec: 0 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} diff --git a/Assets/Materials/Temp3.mat.meta b/Assets/Materials/Temp3.mat.meta new file mode 100644 index 0000000..aabd96e --- /dev/null +++ b/Assets/Materials/Temp3.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 459cd3e0ba7a5fa4490b1d19849b49e2 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/ExplosionTest.cs b/Assets/Scripts/ExplosionTest.cs new file mode 100644 index 0000000..41f6091 --- /dev/null +++ b/Assets/Scripts/ExplosionTest.cs @@ -0,0 +1,22 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ExplosionTest : MonoBehaviour +{ + [SerializeField] + private float Force = 1; + + private void OnTriggerEnter(Collider other) + { + var horse = other.GetComponent(); + + if (horse != null) + { + Vector3 force = Vector3.up * 2 + Vector3.ProjectOnPlane(Random.insideUnitSphere, Vector3.up) * Force; + horse.AddForce(force); + Debug.DrawRay(horse.transform.position, force, Color.red, 1f); + Debug.Log("Throwing horse"); + } + } +} diff --git a/Assets/Scripts/ExplosionTest.cs.meta b/Assets/Scripts/ExplosionTest.cs.meta new file mode 100644 index 0000000..1cb58cd --- /dev/null +++ b/Assets/Scripts/ExplosionTest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1d016e6d7dab5554bb245a972d9d3060 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Input/PlayerController.cs b/Assets/Scripts/Input/PlayerController.cs index 0175610..48c5878 100644 --- a/Assets/Scripts/Input/PlayerController.cs +++ b/Assets/Scripts/Input/PlayerController.cs @@ -131,4 +131,11 @@ public class PlayerController : MonoBehaviour directionRandmoizer = Mathf.Cos(Time.time + randomizer / 2) * 0.3f; UpdatePosition(); } + + public void AddForce(Vector3 direction) + { + moveDirection += direction; + transform.Translate(direction*Time.deltaTime); + } + }