diff --git a/IronToad_UnityProject/Assets/Materials/Test_BoatMat.mat b/IronToad_UnityProject/Assets/Materials/Test_BoatMat.mat index 1ae5549..ed09d5a 100644 Binary files a/IronToad_UnityProject/Assets/Materials/Test_BoatMat.mat and b/IronToad_UnityProject/Assets/Materials/Test_BoatMat.mat differ diff --git a/IronToad_UnityProject/Assets/Models/M_Boat.FBX b/IronToad_UnityProject/Assets/Models/M_Boat.FBX new file mode 100644 index 0000000..1a025d3 Binary files /dev/null and b/IronToad_UnityProject/Assets/Models/M_Boat.FBX differ diff --git a/IronToad_UnityProject/Assets/Models/M_Boat.FBX.meta b/IronToad_UnityProject/Assets/Models/M_Boat.FBX.meta new file mode 100644 index 0000000..4f11a1d --- /dev/null +++ b/IronToad_UnityProject/Assets/Models/M_Boat.FBX.meta @@ -0,0 +1,81 @@ +fileFormatVersion: 2 +guid: 6d2ec77f0914eaa43bb1284587d7d234 +timeCreated: 1484955399 +licenseType: Free +ModelImporter: + serializedVersion: 19 + fileIDToRecycleName: + 100000: //RootNode + 400000: //RootNode + 2300000: //RootNode + 3300000: //RootNode + 4300000: boat + 9500000: //RootNode + materials: + importMaterials: 1 + materialName: 0 + materialSearch: 1 + animations: + legacyGenerateAnimations: 4 + bakeSimulation: 0 + resampleCurves: 1 + optimizeGameObjects: 0 + motionNodeName: + animationImportErrors: + animationImportWarnings: + animationRetargetingWarnings: + animationDoRetargetingWarnings: 0 + animationCompression: 1 + animationRotationError: 0.5 + animationPositionError: 0.5 + animationScaleError: 0.5 + animationWrapMode: 0 + extraExposedTransformPaths: [] + clipAnimations: [] + isReadable: 1 + meshes: + lODScreenPercentages: [] + globalScale: 0.2 + meshCompression: 0 + addColliders: 0 + importBlendShapes: 1 + swapUVChannels: 0 + generateSecondaryUV: 0 + useFileUnits: 1 + optimizeMeshForGPU: 1 + keepQuads: 0 + weldVertices: 1 + secondaryUVAngleDistortion: 8 + secondaryUVAreaDistortion: 15.000001 + secondaryUVHardAngle: 88 + secondaryUVPackMargin: 4 + useFileScale: 1 + tangentSpace: + normalSmoothAngle: 60 + normalImportMode: 0 + tangentImportMode: 3 + importAnimation: 1 + copyAvatar: 0 + humanDescription: + serializedVersion: 2 + human: [] + skeleton: [] + armTwist: 0.5 + foreArmTwist: 0.5 + upperLegTwist: 0.5 + legTwist: 0.5 + armStretch: 0.05 + legStretch: 0.05 + feetSpacing: 0 + rootMotionBoneName: + rootMotionBoneRotation: {x: 0, y: 0, z: 0, w: 1} + hasTranslationDoF: 0 + hasExtraRoot: 0 + skeletonHasParents: 1 + lastHumanDescriptionAvatarSource: {instanceID: 0} + animationType: 2 + humanoidOversampling: 1 + additionalBone: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/IronToad_UnityProject/Assets/Models/Materials.meta b/IronToad_UnityProject/Assets/Models/Materials.meta new file mode 100644 index 0000000..a8df099 --- /dev/null +++ b/IronToad_UnityProject/Assets/Models/Materials.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 09e8828582845e14eaff20477097a3a9 +folderAsset: yes +timeCreated: 1484955399 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/IronToad_UnityProject/Assets/Models/Materials/No Name.mat b/IronToad_UnityProject/Assets/Models/Materials/No Name.mat new file mode 100644 index 0000000..e15f536 Binary files /dev/null and b/IronToad_UnityProject/Assets/Models/Materials/No Name.mat differ diff --git a/IronToad_UnityProject/Assets/Models/Materials/No Name.mat.meta b/IronToad_UnityProject/Assets/Models/Materials/No Name.mat.meta new file mode 100644 index 0000000..169a507 --- /dev/null +++ b/IronToad_UnityProject/Assets/Models/Materials/No Name.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 90392ab8faa788c4198badcacd62f103 +timeCreated: 1484955399 +licenseType: Free +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/IronToad_UnityProject/Assets/Physics Materials.meta b/IronToad_UnityProject/Assets/Physics Materials.meta new file mode 100644 index 0000000..b621718 --- /dev/null +++ b/IronToad_UnityProject/Assets/Physics Materials.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 5448b4db62ef7a84db1e026d5a0ab9f7 +folderAsset: yes +timeCreated: 1484954738 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/IronToad_UnityProject/Assets/Physics Materials/Water.physicMaterial b/IronToad_UnityProject/Assets/Physics Materials/Water.physicMaterial new file mode 100644 index 0000000..bd32d04 Binary files /dev/null and b/IronToad_UnityProject/Assets/Physics Materials/Water.physicMaterial differ diff --git a/IronToad_UnityProject/Assets/Physics Materials/Water.physicMaterial.meta b/IronToad_UnityProject/Assets/Physics Materials/Water.physicMaterial.meta new file mode 100644 index 0000000..e34a01d --- /dev/null +++ b/IronToad_UnityProject/Assets/Physics Materials/Water.physicMaterial.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7306b2bc1a4eb1848aaec35e00857c19 +timeCreated: 1484954750 +licenseType: Free +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/IronToad_UnityProject/Assets/Prefabs.meta b/IronToad_UnityProject/Assets/Prefabs.meta new file mode 100644 index 0000000..a686fa1 --- /dev/null +++ b/IronToad_UnityProject/Assets/Prefabs.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 9b86a2ac850130a4aadb3c416f7faa43 +folderAsset: yes +timeCreated: 1484955477 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/IronToad_UnityProject/Assets/Prefabs/Boat.prefab b/IronToad_UnityProject/Assets/Prefabs/Boat.prefab new file mode 100644 index 0000000..05a9a21 Binary files /dev/null and b/IronToad_UnityProject/Assets/Prefabs/Boat.prefab differ diff --git a/IronToad_UnityProject/Assets/Prefabs/Boat.prefab.meta b/IronToad_UnityProject/Assets/Prefabs/Boat.prefab.meta new file mode 100644 index 0000000..96f29d0 --- /dev/null +++ b/IronToad_UnityProject/Assets/Prefabs/Boat.prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c8aa714f1d5073f43b7d42f73289d5df +timeCreated: 1484957074 +licenseType: Free +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/IronToad_UnityProject/Assets/Prefabs/Crate.prefab b/IronToad_UnityProject/Assets/Prefabs/Crate.prefab new file mode 100644 index 0000000..272032e Binary files /dev/null and b/IronToad_UnityProject/Assets/Prefabs/Crate.prefab differ diff --git a/IronToad_UnityProject/Assets/Prefabs/Crate.prefab.meta b/IronToad_UnityProject/Assets/Prefabs/Crate.prefab.meta new file mode 100644 index 0000000..f4676c2 --- /dev/null +++ b/IronToad_UnityProject/Assets/Prefabs/Crate.prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b708e82a945ea904cb0b2ae0db8244fc +timeCreated: 1484957112 +licenseType: Free +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/IronToad_UnityProject/Assets/Scripts/BoatController.cs b/IronToad_UnityProject/Assets/Scripts/BoatController.cs index 4a0e386..593e77e 100644 --- a/IronToad_UnityProject/Assets/Scripts/BoatController.cs +++ b/IronToad_UnityProject/Assets/Scripts/BoatController.cs @@ -3,19 +3,9 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class BoatController : WaterObject { +public class BoatController : BuoyantObject { - public override void OnWaterEnter() { - throw new NotImplementedException(); - } - - public override void OnWaterStay() { - throw new NotImplementedException(); - } - - public override void OnWaterExit() { - throw new NotImplementedException(); - } + public float trunSpeed = 0.5f; // Use this for initialization @@ -23,8 +13,15 @@ public class BoatController : WaterObject { } - // Update is called once per frame - void Update () { - - } + void Update() { + lookAtDir(Vector3.ProjectOnPlane(rb.velocity, Vector3.up)); + } + + + // Update is called once per frame + void lookAtDir(Vector3 inputDir) { + Quaternion targetRotation = Quaternion.LookRotation(inputDir,Vector3.up); + float str = Mathf.Min(trunSpeed * Time.deltaTime, 1); + transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, str); + } } diff --git a/IronToad_UnityProject/Assets/Scripts/BuoyantObject.cs b/IronToad_UnityProject/Assets/Scripts/BuoyantObject.cs index e88b12e..1e9f72c 100644 --- a/IronToad_UnityProject/Assets/Scripts/BuoyantObject.cs +++ b/IronToad_UnityProject/Assets/Scripts/BuoyantObject.cs @@ -10,33 +10,49 @@ public class BuoyantObject : WaterObject { [Tooltip ("How fast object will raise into the ")] public float BouancyValue = 5; + [Tooltip ("Local point, at which the object floats within the water")] + public Vector3 BouancyPoint = Vector3.zero; + //rigidbody attached to GameObject - private Rigidbody rb; + protected Rigidbody rb; + private float airDrag; + #region Unity Functions void Awake() { + rb = GetComponent(); + airDrag = rb.drag; } + #endregion Unity Functions - #endregion Unity Functions + public override void OnWaterStay(GameObject water,float waveHeight) { + Vector3 waterEntryPoint = transform.position; + waterEntryPoint.y = water.transform.position.y + waveHeight; - public override void OnWaterStay() { - + float distance = Vector3.Distance(transform.position + (BouancyPoint * transform.lossyScale.magnitude) , waterEntryPoint); + Vector3 force = Vector3.up * BouancyValue * Mathf.Pow(distance,1.5f); + if (waterEntryPoint.y < gameObject.transform.position.y + (BouancyPoint.y * transform.lossyScale.y)) + force = Vector3.zero; + rb.AddForce(force); + Vector3 dragVel = rb.velocity; + dragVel.y *= 0.98f; + rb.velocity = dragVel; } - public override void OnWaterEnter() { - throw new NotImplementedException(); + public override void OnWaterEnter(GameObject water) { + //rb.drag = 1; } - public override void OnWaterExit() { - throw new NotImplementedException(); + public override void OnWaterExit(GameObject water) { + // rb.drag = airDrag; } /// diff --git a/IronToad_UnityProject/Assets/Scripts/PlayerController.cs b/IronToad_UnityProject/Assets/Scripts/PlayerController.cs index 90e2946..5efcfcb 100644 --- a/IronToad_UnityProject/Assets/Scripts/PlayerController.cs +++ b/IronToad_UnityProject/Assets/Scripts/PlayerController.cs @@ -4,13 +4,33 @@ using UnityEngine; public class PlayerController : MonoBehaviour { - // Use this for initialization - void Start () { - - } - // Update is called once per frame void Update () { - - } + + if (Input.GetButtonDown("Fire1")) { + Debug.Log("Click"); + RaycastHit hit; + Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); + + LayerMask rayMask = (1 << 4); + + Debug.DrawRay(ray.origin, ray.direction * 100, Color.green); + + if (Physics.Raycast(ray, out hit, Mathf.Infinity,rayMask)) { + WaterController waterScript = hit.collider.gameObject.GetComponent(); + Debug.DrawLine(Camera.main.transform.position, hit.point, Color.red,1); + + Debug.Log("I hit: " + hit.transform.name); + if (waterScript != null) + waterScript.CreateWave(hit.point, 10, 5); + + } + + + } + + + + + } } diff --git a/IronToad_UnityProject/Assets/Scripts/WaterController.cs b/IronToad_UnityProject/Assets/Scripts/WaterController.cs index 9f855ed..79b5105 100644 --- a/IronToad_UnityProject/Assets/Scripts/WaterController.cs +++ b/IronToad_UnityProject/Assets/Scripts/WaterController.cs @@ -4,6 +4,16 @@ using UnityEngine; public class WaterController : MonoBehaviour { + + public AnimationCurve RipplePower; + + private float waveOffset = 0; + public float waveScale = 1; + public float waterWidth = 1; + public float waveSpeed = 1; + public float maxWaveHeight = 2; + + #region Unity Functions // Use this for initialization void Start() { @@ -13,6 +23,8 @@ public class WaterController : MonoBehaviour { // Update is called once per frame void Update() { + waveOffset += 0.1f *waveSpeed * Time.deltaTime; + } #endregion Unity Fucntions @@ -28,25 +40,56 @@ public class WaterController : MonoBehaviour { public void CreateWave(Vector3 point, float radius, float power){ //find all colliders within the wave distance - Collider[] colliders = Physics.OverlapSphere(point, radius); - foreach (Collider hit in colliders) { - Rigidbody rb = hit.GetComponent(); + StartCoroutine(waveController(point, radius, power, 2)); - if (rb != null) - rb.AddExplosionForce(power, point, radius, 0.0f); - } + } + #endregion Interaction Functions + + #region Helper Functions + + public IEnumerator waveController (Vector3 point, float radius, float power, float rippleTime) { + + + float elapsedTime = 0.0f; + + while (elapsedTime < rippleTime) { + + float curRippleForce = RipplePower.Evaluate(elapsedTime / rippleTime); - #endregion Interaction Functions + Collider[] colliders = Physics.OverlapSphere(point, radius); + foreach (Collider hit in colliders) { + + + Rigidbody rb = hit.GetComponent(); + + Debug.DrawLine(point, hit.transform.position, Color.blue, 1); + + if (rb != null) { + Debug.DrawLine(point, hit.transform.position, Color.blue, 1); + Vector3 flatPoint = new Vector3(point.x, hit.transform.position.y, point.z); + rb.AddExplosionForce(power * curRippleForce, point, radius, 0.0f); + } + } + + yield return new WaitForEndOfFrame(); + elapsedTime += Time.deltaTime; + } } + + + + #endregion Helper Functions + + #region Collision Functions void OnTriggerEnter(Collider other) { //calls appropriate function if the object should interact with the water on enter WaterObject waterInteraction = other.gameObject.GetComponent(); if (waterInteraction != null) { - waterInteraction.OnWaterEnter(); + waterInteraction.OnWaterEnter(gameObject); } } @@ -56,7 +99,13 @@ public class WaterController : MonoBehaviour { //calls appropriate function if the object should interact with the water on stay WaterObject waterInteraction = other.gameObject.GetComponent(); if (waterInteraction != null) { - waterInteraction.OnWaterStay(); + + Vector2 waveCoords = new Vector2(other.transform.position.x, other.transform.position.z); + waveCoords = waveCoords / waterWidth * waveScale; + float waveHeight = Mathf.PerlinNoise(waveCoords.x, waveCoords.y + waveOffset); + + + waterInteraction.OnWaterStay(gameObject,waveHeight * maxWaveHeight); } } @@ -65,7 +114,7 @@ public class WaterController : MonoBehaviour { //calls appropriate function if the object should interact with the water on exit WaterObject waterInteraction = other.gameObject.GetComponent(); if (waterInteraction != null) { - waterInteraction.OnWaterExit(); + waterInteraction.OnWaterExit(gameObject); } } diff --git a/IronToad_UnityProject/Assets/Scripts/WaterObject.cs b/IronToad_UnityProject/Assets/Scripts/WaterObject.cs index 2ea5ecf..a15a621 100644 --- a/IronToad_UnityProject/Assets/Scripts/WaterObject.cs +++ b/IronToad_UnityProject/Assets/Scripts/WaterObject.cs @@ -7,17 +7,17 @@ public abstract class WaterObject : MonoBehaviour { /// /// Called when object intersects water plane /// - public abstract void OnWaterEnter(); + public abstract void OnWaterEnter(GameObject water); /// /// Called while objects stays in water /// - public abstract void OnWaterStay(); + public abstract void OnWaterStay(GameObject water,float waveHeight); /// /// Called when object leaves water /// - public abstract void OnWaterExit(); + public abstract void OnWaterExit(GameObject water); } diff --git a/IronToad_UnityProject/Assets/_Scenes/PhysicsTestScene.unity b/IronToad_UnityProject/Assets/_Scenes/PhysicsTestScene.unity index ec4f2e3..cd2e86d 100644 Binary files a/IronToad_UnityProject/Assets/_Scenes/PhysicsTestScene.unity and b/IronToad_UnityProject/Assets/_Scenes/PhysicsTestScene.unity differ