Added basic jump mechanic for slimes and prevention from going over the border, added tile hiding to increase performance
This commit is contained in:
parent
c00a01c8d6
commit
a8cca74fc4
@ -116,10 +116,10 @@ Rigidbody:
|
|||||||
m_PrefabInstance: {fileID: 0}
|
m_PrefabInstance: {fileID: 0}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 4392939395195199552}
|
m_GameObject: {fileID: 4392939395195199552}
|
||||||
serializedVersion: 4
|
serializedVersion: 5
|
||||||
m_Mass: 1
|
m_Mass: 1
|
||||||
m_Drag: 0
|
m_LinearDamping: 0
|
||||||
m_AngularDrag: 0.05
|
m_AngularDamping: 0.05
|
||||||
m_CenterOfMass: {x: 0, y: 0, z: 0}
|
m_CenterOfMass: {x: 0, y: 0, z: 0}
|
||||||
m_InertiaTensor: {x: 1, y: 1, z: 1}
|
m_InertiaTensor: {x: 1, y: 1, z: 1}
|
||||||
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
@ -134,7 +134,7 @@ Rigidbody:
|
|||||||
m_UseGravity: 1
|
m_UseGravity: 1
|
||||||
m_IsKinematic: 0
|
m_IsKinematic: 0
|
||||||
m_Interpolate: 0
|
m_Interpolate: 0
|
||||||
m_Constraints: 122
|
m_Constraints: 112
|
||||||
m_CollisionDetection: 0
|
m_CollisionDetection: 0
|
||||||
--- !u!114 &-9044075018784067105
|
--- !u!114 &-9044075018784067105
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
@ -150,3 +150,4 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
clip: {fileID: 0}
|
clip: {fileID: 0}
|
||||||
keepAlive: 0
|
keepAlive: 0
|
||||||
|
slimeType: 0
|
||||||
|
|||||||
@ -116,10 +116,10 @@ Rigidbody:
|
|||||||
m_PrefabInstance: {fileID: 0}
|
m_PrefabInstance: {fileID: 0}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 7849292920502973565}
|
m_GameObject: {fileID: 7849292920502973565}
|
||||||
serializedVersion: 4
|
serializedVersion: 5
|
||||||
m_Mass: 1
|
m_Mass: 1
|
||||||
m_Drag: 0
|
m_LinearDamping: 0
|
||||||
m_AngularDrag: 0.05
|
m_AngularDamping: 0.05
|
||||||
m_CenterOfMass: {x: 0, y: 0, z: 0}
|
m_CenterOfMass: {x: 0, y: 0, z: 0}
|
||||||
m_InertiaTensor: {x: 1, y: 1, z: 1}
|
m_InertiaTensor: {x: 1, y: 1, z: 1}
|
||||||
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
@ -134,7 +134,7 @@ Rigidbody:
|
|||||||
m_UseGravity: 1
|
m_UseGravity: 1
|
||||||
m_IsKinematic: 0
|
m_IsKinematic: 0
|
||||||
m_Interpolate: 0
|
m_Interpolate: 0
|
||||||
m_Constraints: 122
|
m_Constraints: 112
|
||||||
m_CollisionDetection: 0
|
m_CollisionDetection: 0
|
||||||
--- !u!114 &525370201721428245
|
--- !u!114 &525370201721428245
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
|
|||||||
@ -116,10 +116,10 @@ Rigidbody:
|
|||||||
m_PrefabInstance: {fileID: 0}
|
m_PrefabInstance: {fileID: 0}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 379562847455873462}
|
m_GameObject: {fileID: 379562847455873462}
|
||||||
serializedVersion: 4
|
serializedVersion: 5
|
||||||
m_Mass: 1
|
m_Mass: 1
|
||||||
m_Drag: 0
|
m_LinearDamping: 0
|
||||||
m_AngularDrag: 0.05
|
m_AngularDamping: 0.05
|
||||||
m_CenterOfMass: {x: 0, y: 0, z: 0}
|
m_CenterOfMass: {x: 0, y: 0, z: 0}
|
||||||
m_InertiaTensor: {x: 1, y: 1, z: 1}
|
m_InertiaTensor: {x: 1, y: 1, z: 1}
|
||||||
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
@ -134,7 +134,7 @@ Rigidbody:
|
|||||||
m_UseGravity: 1
|
m_UseGravity: 1
|
||||||
m_IsKinematic: 0
|
m_IsKinematic: 0
|
||||||
m_Interpolate: 0
|
m_Interpolate: 0
|
||||||
m_Constraints: 122
|
m_Constraints: 112
|
||||||
m_CollisionDetection: 0
|
m_CollisionDetection: 0
|
||||||
--- !u!114 &4274648213253980113
|
--- !u!114 &4274648213253980113
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
|
|||||||
@ -116,10 +116,10 @@ Rigidbody:
|
|||||||
m_PrefabInstance: {fileID: 0}
|
m_PrefabInstance: {fileID: 0}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 6968562527232053028}
|
m_GameObject: {fileID: 6968562527232053028}
|
||||||
serializedVersion: 4
|
serializedVersion: 5
|
||||||
m_Mass: 1
|
m_Mass: 1
|
||||||
m_Drag: 0
|
m_LinearDamping: 0
|
||||||
m_AngularDrag: 0.05
|
m_AngularDamping: 0.05
|
||||||
m_CenterOfMass: {x: 0, y: 0, z: 0}
|
m_CenterOfMass: {x: 0, y: 0, z: 0}
|
||||||
m_InertiaTensor: {x: 1, y: 1, z: 1}
|
m_InertiaTensor: {x: 1, y: 1, z: 1}
|
||||||
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
@ -134,7 +134,7 @@ Rigidbody:
|
|||||||
m_UseGravity: 1
|
m_UseGravity: 1
|
||||||
m_IsKinematic: 0
|
m_IsKinematic: 0
|
||||||
m_Interpolate: 0
|
m_Interpolate: 0
|
||||||
m_Constraints: 122
|
m_Constraints: 112
|
||||||
m_CollisionDetection: 0
|
m_CollisionDetection: 0
|
||||||
--- !u!114 &3695996598061783199
|
--- !u!114 &3695996598061783199
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
|
|||||||
@ -116,10 +116,10 @@ Rigidbody:
|
|||||||
m_PrefabInstance: {fileID: 0}
|
m_PrefabInstance: {fileID: 0}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 710453253311522916}
|
m_GameObject: {fileID: 710453253311522916}
|
||||||
serializedVersion: 4
|
serializedVersion: 5
|
||||||
m_Mass: 1
|
m_Mass: 1
|
||||||
m_Drag: 0
|
m_LinearDamping: 0
|
||||||
m_AngularDrag: 0.05
|
m_AngularDamping: 0.05
|
||||||
m_CenterOfMass: {x: 0, y: 0, z: 0}
|
m_CenterOfMass: {x: 0, y: 0, z: 0}
|
||||||
m_InertiaTensor: {x: 1, y: 1, z: 1}
|
m_InertiaTensor: {x: 1, y: 1, z: 1}
|
||||||
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
@ -134,7 +134,7 @@ Rigidbody:
|
|||||||
m_UseGravity: 1
|
m_UseGravity: 1
|
||||||
m_IsKinematic: 0
|
m_IsKinematic: 0
|
||||||
m_Interpolate: 0
|
m_Interpolate: 0
|
||||||
m_Constraints: 122
|
m_Constraints: 112
|
||||||
m_CollisionDetection: 0
|
m_CollisionDetection: 0
|
||||||
--- !u!114 &6506905793749053412
|
--- !u!114 &6506905793749053412
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
|
|||||||
@ -116,10 +116,10 @@ Rigidbody:
|
|||||||
m_PrefabInstance: {fileID: 0}
|
m_PrefabInstance: {fileID: 0}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 7591882314654710750}
|
m_GameObject: {fileID: 7591882314654710750}
|
||||||
serializedVersion: 4
|
serializedVersion: 5
|
||||||
m_Mass: 1
|
m_Mass: 1
|
||||||
m_Drag: 0
|
m_LinearDamping: 0
|
||||||
m_AngularDrag: 0.05
|
m_AngularDamping: 0.05
|
||||||
m_CenterOfMass: {x: 0, y: 0, z: 0}
|
m_CenterOfMass: {x: 0, y: 0, z: 0}
|
||||||
m_InertiaTensor: {x: 1, y: 1, z: 1}
|
m_InertiaTensor: {x: 1, y: 1, z: 1}
|
||||||
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
@ -134,7 +134,7 @@ Rigidbody:
|
|||||||
m_UseGravity: 1
|
m_UseGravity: 1
|
||||||
m_IsKinematic: 0
|
m_IsKinematic: 0
|
||||||
m_Interpolate: 0
|
m_Interpolate: 0
|
||||||
m_Constraints: 122
|
m_Constraints: 112
|
||||||
m_CollisionDetection: 0
|
m_CollisionDetection: 0
|
||||||
--- !u!114 &-1716680456059707178
|
--- !u!114 &-1716680456059707178
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
|
|||||||
@ -6,6 +6,7 @@ using System;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace Assets.Scripts.InteractableObjects
|
namespace Assets.Scripts.InteractableObjects
|
||||||
{
|
{
|
||||||
@ -15,6 +16,53 @@ namespace Assets.Scripts.InteractableObjects
|
|||||||
BasicSlime slime;
|
BasicSlime slime;
|
||||||
SlimeFactory factory = new SlimeFactory();
|
SlimeFactory factory = new SlimeFactory();
|
||||||
public SlimeType slimeType;
|
public SlimeType slimeType;
|
||||||
|
bool isJumping;
|
||||||
|
Stopwatch jumpTimer;
|
||||||
|
|
||||||
|
// Start is called before the first frame update
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
isJumping = false;
|
||||||
|
jumpTimer = new Stopwatch();
|
||||||
|
//Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
if (gameObject.activeSelf)
|
||||||
|
{
|
||||||
|
if (!isJumping)
|
||||||
|
{
|
||||||
|
jumpTimer.Start();
|
||||||
|
isJumping = true;
|
||||||
|
gameObject.GetComponent<Rigidbody>().AddForce(new Vector3(rand.Next(-5, 5), 10, rand.Next(-5, 5)), ForceMode.Impulse);
|
||||||
|
//gameObject.GetComponent<Rigidbody>().AddForce(new Vector3(5, 10, 5), ForceMode.Impulse);
|
||||||
|
}
|
||||||
|
if (jumpTimer.ElapsedMilliseconds >= 5000)
|
||||||
|
{
|
||||||
|
jumpTimer.Reset();
|
||||||
|
isJumping = false;
|
||||||
|
}
|
||||||
|
if (gameObject.transform.position.x > 1000 || gameObject.transform.position.x > 5000 || gameObject.transform.position.x > 5000)
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.Log("BUG!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnTriggerExit(Collider col)
|
||||||
|
{
|
||||||
|
if (col.name.Contains("_") && col.gameObject == gameObject.transform.parent.gameObject)
|
||||||
|
{
|
||||||
|
gameObject.GetComponent<Rigidbody>().AddForce(gameObject.GetComponent<Rigidbody>().linearVelocity * -2, ForceMode.Impulse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnDisable()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public override void handleInteraction(GameObject player)
|
public override void handleInteraction(GameObject player)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -224,15 +224,8 @@ namespace Assets.Scripts.Player
|
|||||||
{
|
{
|
||||||
worldGenerator.changeCurrentTile(col.gameObject);
|
worldGenerator.changeCurrentTile(col.gameObject);
|
||||||
|
|
||||||
worldGenerator.createTile(new Vector3(-1, 0, 0));
|
worldGenerator.generateMissingTiles();
|
||||||
worldGenerator.createTile(new Vector3(1, 0, 0));
|
worldGenerator.hideFarTiles();
|
||||||
worldGenerator.createTile(new Vector3(0, 0, 1));
|
|
||||||
worldGenerator.createTile(new Vector3(0, 0, -1));
|
|
||||||
|
|
||||||
worldGenerator.createTile(new Vector3(-1, 0, -1));
|
|
||||||
worldGenerator.createTile(new Vector3(1, 0, -1));
|
|
||||||
worldGenerator.createTile(new Vector3(-1, 0, 1));
|
|
||||||
worldGenerator.createTile(new Vector3(1, 0, 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (col.name.Contains("House"))
|
if (col.name.Contains("House"))
|
||||||
|
|||||||
@ -29,6 +29,16 @@ public class Tile : MonoBehaviour
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void show()
|
||||||
|
{
|
||||||
|
gameObject.SetActive(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hide()
|
||||||
|
{
|
||||||
|
gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
public void generateContent()
|
public void generateContent()
|
||||||
{
|
{
|
||||||
foreach (Vector3 position in getSpawnLocations())
|
foreach (Vector3 position in getSpawnLocations())
|
||||||
|
|||||||
@ -96,6 +96,57 @@ public class WorldGenerator : MonoBehaviour
|
|||||||
newTile.GetComponent<Tile>().generateTile(pos, (TileType)Enum.Parse(typeof(TileType), newTile.name.Split("_")[0]));
|
newTile.GetComponent<Tile>().generateTile(pos, (TileType)Enum.Parse(typeof(TileType), newTile.name.Split("_")[0]));
|
||||||
tiles.Add(pos, newTile);
|
tiles.Add(pos, newTile);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tiles[pos].GetComponent<Tile>().show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hideTile(Vector3 requiredPosition)
|
||||||
|
{
|
||||||
|
Vector3 pos = currentTile.GetComponent<Tile>().getPosition() + requiredPosition;
|
||||||
|
if (tiles.ContainsKey(pos) && pos.y == 0)
|
||||||
|
{
|
||||||
|
tiles[pos].GetComponent<Tile>().hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void generateMissingTiles()
|
||||||
|
{
|
||||||
|
createTile(new Vector3(-1, 0, 0));
|
||||||
|
createTile(new Vector3(1, 0, 0));
|
||||||
|
createTile(new Vector3(0, 0, 1));
|
||||||
|
createTile(new Vector3(0, 0, -1));
|
||||||
|
|
||||||
|
createTile(new Vector3(-1, 0, -1));
|
||||||
|
createTile(new Vector3(1, 0, -1));
|
||||||
|
createTile(new Vector3(-1, 0, 1));
|
||||||
|
createTile(new Vector3(1, 0, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hideFarTiles()
|
||||||
|
{
|
||||||
|
hideTile(new Vector3(-2, 0, -2));
|
||||||
|
hideTile(new Vector3(-2, 0, -1));
|
||||||
|
hideTile(new Vector3(-2, 0, 0));
|
||||||
|
hideTile(new Vector3(-2, 0, 1));
|
||||||
|
hideTile(new Vector3(-2, 0, 2));
|
||||||
|
|
||||||
|
hideTile(new Vector3(2, 0, -2));
|
||||||
|
hideTile(new Vector3(2, 0, -1));
|
||||||
|
hideTile(new Vector3(2, 0, 0));
|
||||||
|
hideTile(new Vector3(2, 0, 1));
|
||||||
|
hideTile(new Vector3(2, 0, 2));
|
||||||
|
|
||||||
|
hideTile(new Vector3(-1, 0, -2));
|
||||||
|
hideTile(new Vector3(0, 0, -2));
|
||||||
|
hideTile(new Vector3(1, 0, -2));
|
||||||
|
hideTile(new Vector3(2, 0, -2));
|
||||||
|
|
||||||
|
hideTile(new Vector3(-2, 0, 2));
|
||||||
|
hideTile(new Vector3(-1, 0, 2));
|
||||||
|
hideTile(new Vector3(0, 0, 2));
|
||||||
|
hideTile(new Vector3(1, 0, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeCurrentTile(GameObject newCurrent)
|
public void changeCurrentTile(GameObject newCurrent)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user