Commit eae17825 authored by Mitchie Maluschnig's avatar Mitchie Maluschnig
Browse files

better procedural generation of trapezes, camera now zooms out when player in mid air

parent 7a9bcf5c
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_RemovedComponents: []
m_SourcePrefab: {fileID: 0}
m_RootGameObject: {fileID: 1308170843970902}
m_IsPrefabAsset: 1
--- !u!1 &1308170843970902
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 6
m_Component:
- component: {fileID: 4984355063605358}
- component: {fileID: 212954946472709068}
- component: {fileID: 70346896267999526}
- component: {fileID: 68677398153341540}
m_Layer: 8
m_Name: rope 1
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4984355063605358
Transform:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1308170843970902}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -19.04, y: -55.829998, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!68 &68677398153341540
EdgeCollider2D:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1308170843970902}
m_Enabled: 0
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_EdgeRadius: 0
m_Points:
- {x: -2.5, y: 0}
- {x: 2.5, y: 0}
--- !u!70 &70346896267999526
CapsuleCollider2D:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1308170843970902}
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.06}
m_Size: {x: 5, y: 0.6}
m_Direction: 1
--- !u!212 &212954946472709068
SpriteRenderer:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1308170843970902}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 4294967295
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_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: abc7c8627cab5494da8e4bd5f24a5796, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 5, y: 0.86}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
fileFormatVersion: 2
guid: cfb62dab04de2fe4da7137a2f627086b
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GenerateTrapezes : MonoBehaviour {
public GameObject trapeze;
public float AvgXSepparation = 10;
public float XDifference = 0.8f;
public float YRange = 2;
public float maxYrange = 10;
private GameObject player;
private Transform playerHands;
private Transform[] initialTrapezes = new Transform[3];
private Transform[] currentTrapezeInLevel = new Transform[3];
private int numTrapezes;
// Use this for initialization
void Start () {
player = GameObject.FindWithTag("Player");
playerHands = GameObject.FindWithTag("Hands").transform;
//first trapeze
Transform firstTrapeze = Instantiate(trapeze, playerHands.position, Quaternion.identity).transform;
//next 3 trapezes
Vector3 newTrapeze = firstTrapeze.position;
newTrapeze.x += AvgXSepparation;
newTrapeze.y += -YRange * 2;
initialTrapezes[0] = Instantiate(trapeze, newTrapeze, Quaternion.identity).transform;
currentTrapezeInLevel[0] = initialTrapezes[0];
newTrapeze.y += YRange * 2;
initialTrapezes[1] = Instantiate(trapeze, newTrapeze, Quaternion.identity).transform;
currentTrapezeInLevel[1] = initialTrapezes[1];
newTrapeze.y += YRange * 2;
initialTrapezes[2] = Instantiate(trapeze, newTrapeze, Quaternion.identity).transform;
currentTrapezeInLevel[2] = initialTrapezes[2];
}
// Update is called once per frame
void Update () {
//for (int i = 0; i < currentTrapezeInLevel.Length; i++) {
// if (currentTrapezeInLevel[i].position.x <= playerHands.position.x + 2 * AvgXSepparation) {
// Vector3 newTrapeze = currentTrapezeInLevel[i].position;
// newTrapeze.x += AvgXSepparation;
// newTrapeze.y = Mathf.Clamp(Random.Range(newTrapeze.y - YRange, newTrapeze.y + YRange),initialTrapezes[i].position.y - maxYrange, initialTrapezes[i].position.y + maxYrange);
// currentTrapezeInLevel[i] = Instantiate(trapeze, newTrapeze, Quaternion.identity).transform;
// }
//}
//second way
for (int i = 0; i < currentTrapezeInLevel.Length; i++) {
if (currentTrapezeInLevel[i].position.x <= playerHands.position.x + 2 * AvgXSepparation/*use camera stuff maybe*/) {
Vector3 newTrapeze = initialTrapezes[i].position;
newTrapeze.x = currentTrapezeInLevel[i].position.x + Random.Range(AvgXSepparation * XDifference, AvgXSepparation / XDifference);
newTrapeze.y = Random.Range(newTrapeze.y - YRange, newTrapeze.y + YRange);
currentTrapezeInLevel[i] = Instantiate(trapeze, newTrapeze, Quaternion.identity).transform;
}
}
}
}
fileFormatVersion: 2
guid: 31254c6f65256ba4c9307fb498b2398e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -24,6 +24,12 @@ public class HandsTrigger : MonoBehaviour {
if (!trapezePerson.onTrapeze) {
//possibly enable this trapeze after a second
if (!collision.gameObject.Equals(lastTrapeze)) {
if (collision.gameObject.tag == "LowRope") {
trapezePerson.exitForce = 4;
//have a trampoline that bounces to the next platform (x coordinate-wise)
} else {
trapezePerson.exitForce = 2;
}
lastTrapeze = collision.gameObject;
trapezePerson.AttachToTrapeze(collision.gameObject);
}
......
......@@ -4,6 +4,12 @@ using UnityEngine;
public class TrapezeCameraFollow : MonoBehaviour {
public float maxZoom = 10;
public float minZoom = 30;
public float zoomInRate = 5;
public float zoomOutRate = 0.5f;
private GameObject player;
private TrapezePerson playerScript;
// Use this for initialization
......@@ -19,5 +25,13 @@ public class TrapezeCameraFollow : MonoBehaviour {
playerPos.z = Camera.main.transform.position.z;
Camera.main.transform.position = playerPos;
if (playerScript.onTrapeze) {
float zoom = Mathf.Lerp(Camera.main.orthographicSize, maxZoom, zoomInRate * Time.deltaTime);
Camera.main.orthographicSize = zoom;
} else {
float zoom = Mathf.Lerp(Camera.main.orthographicSize, minZoom, zoomOutRate * Time.deltaTime);
Camera.main.orthographicSize = zoom;
}
}
}
......@@ -13,7 +13,7 @@ public class TrapezePerson : MonoBehaviour {
private HingeJoint2D hinge;
private Rigidbody2D body;
private HandsTrigger handsTrigger;
private HandsTrigger handsTrigger;
[HideInInspector]
public Transform currentPivot;
......@@ -49,24 +49,16 @@ public class TrapezePerson : MonoBehaviour {
transform.RotateAround(currentPivot.position, Vector3.forward, rotateForce);
}
}
if (Input.GetKeyDown(KeyCode.Space)) {
if (onTrapeze && Input.GetKeyDown(KeyCode.Space)) {
float radius = Vector3.Distance(transform.position, botPivot.position);
float radiansPerSecond = body.angularVelocity * Mathf.PI / 180;
linearVelocity = radius * radiansPerSecond;
DetachFromTrapeze();
}
}
//***this has been moved to HandsTrigger.cs***
//void OnTriggerEnter2D(Collider2D collision) {
// if (collision.gameObject.layer == LayerMask.NameToLayer("Key")) {
// print("Collision");
// if (!onTrapeze) {
// AttachToTrapeze(collision.gameObject);
// }
// }
//}
//***Collision triggers moved to HandsTrigger.cs***
public void AttachToTrapeze(GameObject trapeze) {
onTrapeze = true;
......@@ -75,16 +67,14 @@ public class TrapezePerson : MonoBehaviour {
//GetComponent<CapsuleCollider2D>().enabled = true;
currentTrapeze = trapeze;
Time.timeScale = 1;
swingForce /= 2;
}
public void DetachFromTrapeze() {
currentPivot = midPivot;
hinge.enabled = false;
onTrapeze = false;
body.velocity = linearVelocity * exitForce * transform.right;
Time.timeScale = 0.5f;
swingForce *= 2;
body.velocity = linearVelocity * exitForce * transform.right;//scale exit force by velocity so that fast players dont get super air
//Time.timeScale = 0.5f;
body.angularVelocity = 0;
StartCoroutine(handsTrigger.reactivateTrapeze());
}
......
......@@ -16,6 +16,8 @@ TagManager:
- LevelMaster
- TriggerManager
- Silas
- Hands
- LowRope
layers:
- Default
- TransparentFX
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment