157 changed files with 80128 additions and 6 deletions
Binary file not shown.
@ -0,0 +1,8 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 9c931f99cfa582546bddd73d8a7d07bf |
|||
timeCreated: 1462719009 |
|||
licenseType: Free |
|||
NativeFormatImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
@ -0,0 +1,9 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 053263c9d21d1a04eab7b3e986bda45a |
|||
folderAsset: yes |
|||
timeCreated: 1463189201 |
|||
licenseType: Free |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
@ -0,0 +1,120 @@ |
|||
using UnityEngine; |
|||
using System.Collections; |
|||
|
|||
namespace CharacterEngine.Primitives |
|||
{ |
|||
public sealed class CECollider |
|||
{ |
|||
public static int[,] edges = new int[,] |
|||
{ |
|||
{0, 4}, {0, 2}, {0, 6}, |
|||
{1, 7}, {1, 5}, {1, 3}, |
|||
{3, 4}, {3, 2}, {6, 5}, |
|||
{6, 7}, {7, 2}, {5, 4} |
|||
}; |
|||
|
|||
public static int[,] faces = new int[,] |
|||
{ |
|||
{0, 3}, {0, 5}, {0, 7}, |
|||
{1, 6}, {1, 4}, {1, 2} |
|||
}; |
|||
|
|||
private Collider collider; |
|||
public Collider Coll |
|||
{ |
|||
get { return collider; } |
|||
} |
|||
|
|||
public Vector3 position |
|||
{ |
|||
get { return collider.bounds.center; } |
|||
} |
|||
|
|||
public readonly Vector3[] localPoints; |
|||
|
|||
public CECollider (Collider coll) |
|||
{ |
|||
collider = coll; |
|||
|
|||
///COLLIDER CONSTANT RELATIVE POINTS
|
|||
localPoints = new Vector3[] |
|||
{ |
|||
coll.bounds.size * 0.5f, //max
|
|||
-coll.bounds.size * 0.5f, //min
|
|||
new Vector3(-coll.bounds.extents.x, coll.bounds.extents.y, coll.bounds.extents.z), |
|||
new Vector3(-coll.bounds.extents.x, coll.bounds.extents.y, -coll.bounds.extents.z), |
|||
new Vector3(coll.bounds.extents.x, coll.bounds.extents.y, -coll.bounds.extents.z), |
|||
new Vector3(coll.bounds.extents.x, -coll.bounds.extents.y, -coll.bounds.extents.z), |
|||
new Vector3(coll.bounds.extents.x, -coll.bounds.extents.y, coll.bounds.extents.z), |
|||
new Vector3(-coll.bounds.extents.x, -coll.bounds.extents.y, coll.bounds.extents.z) |
|||
}; |
|||
} |
|||
|
|||
public Vector3 GetPoint (int index) |
|||
{ |
|||
return position + localPoints[index]; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Collision test along a path
|
|||
/// </summary>
|
|||
public RaycastHit SweepTest(Vector3 dir, float distance, float skinWidth = 1.0f) |
|||
{ |
|||
RaycastHit hit = new RaycastHit(); |
|||
|
|||
for (int i = 0; i <= CEPrimitives.sweepResolution; i++) |
|||
{ |
|||
Vector3 currentDistance = dir.normalized * (distance * (i / CEPrimitives.sweepResolution)); |
|||
hit = BoxCast(position + currentDistance, skinWidth); |
|||
|
|||
if (hit.distance != 0.0f) break; |
|||
} |
|||
|
|||
return hit; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Collision test in an specific point
|
|||
/// </summary>
|
|||
public RaycastHit BoxCast(Vector3 position, float skinWidth = 1.0f) |
|||
{ |
|||
int mask = LayerMask.GetMask("Default"); |
|||
|
|||
RaycastHit outHit = new RaycastHit(); |
|||
|
|||
///FACE CAST
|
|||
for (int i = 0; i < faces.GetLength(0); i++) |
|||
{ |
|||
//Debug.DrawLine(points[faces[i, 0]], points[faces[i, 1]], Color.blue);
|
|||
|
|||
if (!Physics.Linecast(position + localPoints[faces[i, 0]] * skinWidth, position + localPoints[faces[i, 1]] * skinWidth, out outHit, mask, QueryTriggerInteraction.Ignore)) |
|||
{ |
|||
continue; |
|||
} |
|||
|
|||
///RETURN DISTANCE FROM CENTER
|
|||
return outHit; |
|||
} |
|||
|
|||
///EDGE CAST
|
|||
for (int i = 0; i < CECollider.edges.GetLength(0); i++) |
|||
{ |
|||
//Debug.DrawLine(points[edges[i, 0]], points[edges[i, 1]], Color.red);
|
|||
|
|||
if (!Physics.Linecast(position + localPoints[edges[i, 0]] * skinWidth, position + localPoints[edges[i, 1]] * skinWidth, out outHit, mask, QueryTriggerInteraction.Ignore)) |
|||
{ |
|||
if (!Physics.Linecast(position + localPoints[edges[i, 1]] * skinWidth, position + localPoints[edges[i, 0]] * skinWidth, out outHit, mask, QueryTriggerInteraction.Ignore)) |
|||
{ |
|||
continue; |
|||
} |
|||
} |
|||
|
|||
///RETURN DISTANCE FROM CENTER
|
|||
return outHit; |
|||
} |
|||
|
|||
///IF REACH HERE DIDNT FOUND SHIT
|
|||
return outHit; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 81aea943a0d329749bef1a54a294d002 |
|||
timeCreated: 1463190605 |
|||
licenseType: Free |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
@ -0,0 +1,57 @@ |
|||
using UnityEngine; |
|||
using System.Collections; |
|||
using CharacterEngine.Primitives; |
|||
|
|||
namespace CharacterEngine.Controller |
|||
{ |
|||
public class CEController : MonoBehaviour |
|||
{ |
|||
|
|||
#region Public Custom Fields
|
|||
|
|||
[Range(0.5f, 3.0f)] |
|||
public float skinWidth = 1.0f; |
|||
|
|||
[Range(0.0f, 5.0f)] |
|||
public float weight = 1.0f; |
|||
|
|||
#endregion
|
|||
|
|||
private CEPrimitives primitives; |
|||
|
|||
/*Summary: |
|||
Initializer region contains both native unity initalizers of monobehaviour, Awake is called ONLY ONCE IN |
|||
LIFE TIME, and is called when the object is being created, before Start. Start in the other hand, is called |
|||
when the object is enable and ready. |
|||
*/ |
|||
|
|||
void Awake () |
|||
{ |
|||
primitives = new CEPrimitives(this); |
|||
} |
|||
|
|||
// Use this for initialization
|
|||
void Start() |
|||
{ |
|||
|
|||
} |
|||
|
|||
/*Summary: |
|||
In Updates, we have both functions native from unity Monobehaviour: Update & FixedUpdate. |
|||
The difference of this both is that one (Update) excecute every frame, and the other one, is executed |
|||
by a fixed time (Fixed Update) which is by default 0.02s = 20 ms, that means "Update" depends on the framerate |
|||
while "Fixed Update" dont. |
|||
*/ |
|||
|
|||
// Update is called once per frame
|
|||
void Update() |
|||
{ |
|||
|
|||
} |
|||
|
|||
void FixedUpdate () |
|||
{ |
|||
primitives.Step(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 0e35b01539b765e439f694ed7e8a7022 |
|||
timeCreated: 1463189467 |
|||
licenseType: Free |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
@ -0,0 +1,151 @@ |
|||
using UnityEngine; |
|||
using System.Collections; |
|||
using CharacterEngine.Controller; |
|||
|
|||
namespace CharacterEngine.Primitives |
|||
{ |
|||
public sealed class CEPrimitives |
|||
{ |
|||
#region Controller Globals
|
|||
|
|||
public const int sweepResolution = 3; |
|||
|
|||
private static float gravity = -8.0f; |
|||
public static float Gravity |
|||
{ |
|||
get { return gravity; } |
|||
set { gravity = value; } |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
#region Controller Variables
|
|||
|
|||
private CEController controller; |
|||
public readonly CECollider collider; |
|||
|
|||
private Vector3 velocity; |
|||
public Vector3 Velocity |
|||
{ |
|||
get { return velocity; } |
|||
} |
|||
|
|||
public Transform transform |
|||
{ |
|||
get { return controller.transform; } |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
#region Initializers & Constructors
|
|||
|
|||
public CEPrimitives (CEController controller) |
|||
{ |
|||
this.controller = controller; |
|||
collider = new CECollider(controller.GetComponent<Collider>()); |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
#region Steps
|
|||
|
|||
/*Summary: |
|||
Here in steps, there are the methods called in the UPDATES, that means that every step |
|||
will be executed every frame. |
|||
*/ |
|||
|
|||
public void Step () |
|||
{ |
|||
PhysicsStep(); |
|||
} |
|||
|
|||
void PhysicsStep() |
|||
{ |
|||
GetVelocity(); |
|||
|
|||
GravityStep(); |
|||
CollisionStep(); |
|||
|
|||
ApplyVelocity(); |
|||
Move(); |
|||
} |
|||
|
|||
void GetVelocity() |
|||
{ |
|||
|
|||
} |
|||
|
|||
void GravityStep() |
|||
{ |
|||
velocity.y += gravity * controller.weight * Time.deltaTime * 1.2f; |
|||
velocity.x = -gravity * 0.5f; |
|||
} |
|||
|
|||
void CollisionStep() |
|||
{ |
|||
for (int i = 0; i < 5; i++) |
|||
if (!CollideAndSlide()) break; |
|||
} |
|||
|
|||
bool CollideAndSlide() |
|||
{ |
|||
Vector3 oldPos = transform.position; |
|||
Vector3 predictedPos = oldPos + velocity * Time.fixedDeltaTime; |
|||
Vector3 correctedPos = predictedPos; |
|||
|
|||
RaycastHit hit = collider.SweepTest(velocity, velocity.magnitude * Time.fixedDeltaTime, controller.skinWidth); |
|||
|
|||
if (hit.collider == null) { return false; } |
|||
|
|||
Vector3 obstacleHitPoint = hit.point; |
|||
Vector3 obstacleNormal = hit.normal; |
|||
Vector3 obstacleTangent = Vector3.Cross(obstacleNormal, Vector3.forward); |
|||
if (obstacleTangent.magnitude == 0) |
|||
obstacleTangent = Vector3.Cross(obstacleNormal, Vector3.up); |
|||
|
|||
/* |
|||
Plane obstaclePlane = new Plane(obstacleNormal, obstacleHitPoint); |
|||
Ray velRay = new Ray(oldPos, velocity); |
|||
float distanceFromPlane = 0.0f; |
|||
|
|||
obstaclePlane.Raycast(velRay, out distanceFromPlane); |
|||
Vector3 vectorFromCenter = obstacleHitPoint - Coll.bounds.center ; |
|||
*/ |
|||
|
|||
correctedPos = oldPos + velocity.normalized * hit.distance; |
|||
|
|||
/* |
|||
GameObject a = Instantiate(this.gameObject, correctedPos, transform.rotation) as GameObject; |
|||
a.GetComponent<EntityController>().enabled = false; |
|||
*/ |
|||
|
|||
Vector3 epsilon = correctedPos - predictedPos; |
|||
|
|||
/* |
|||
Vector3 normalForce = Vector3.Dot(obstacleNormal, oldVel) * obstacleNormal; |
|||
|
|||
newVel = oldVel - normalForce; |
|||
//newVel = (oldVel.magnitude / newVel.magnitude) * newVel;
|
|||
*/ |
|||
|
|||
Vector3 projectedForce = Vector3.Project(velocity, obstacleTangent); |
|||
|
|||
velocity = projectedForce; |
|||
velocity.z = 0.0f; |
|||
|
|||
return true; |
|||
} |
|||
|
|||
void ApplyVelocity() |
|||
{ |
|||
Debug.DrawRay(transform.position, velocity); |
|||
} |
|||
|
|||
void Move() |
|||
{ |
|||
transform.position += velocity * Time.deltaTime; |
|||
} |
|||
|
|||
#endregion
|
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 4dec4b65dcbaa4440ad5eaa237496cda |
|||
timeCreated: 1462738429 |
|||
licenseType: Free |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
Binary file not shown.
@ -1 +1 @@ |
|||
5;0;-1 |
|||
5;0;6;-1 |
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,4 @@ |
|||
sceneSetups: |
|||
- path: Assets/_Scenes/Minigame.unity |
|||
isLoaded: 1 |
|||
isActive: 1 |
|||
@ -1,2 +1,2 @@ |
|||
unityRebuildLibraryVersion: 10 |
|||
unityRebuildLibraryVersion: 11 |
|||
unityForwardCompatibleVersion: 40 |
|||
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,2 +1,2 @@ |
|||
0000.55511fec.0000 |
|||
0000.5551202e.0000 |
|||
0000.56e24096.0000 |
|||
0000.56e240a6.0000 |
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Binary file not shown.
File diff suppressed because it is too large
Binary file not shown.
File diff suppressed because it is too large
Binary file not shown.
File diff suppressed because it is too large
@ -0,0 +1,6 @@ |
|||
5.3.4f1:2.2.0.0 |
|||
StandaloneWindows |
|||
C:/Program Files/Unity/Editor/Data/Managed/UnityEngine.dll |
|||
C:/Program Files/Unity/Editor/Data/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll |
|||
C:/Program Files/Unity/Editor/Data/UnityExtensions/Unity/Networking/UnityEngine.Networking.dll |
|||
C:/Program Files/Unity/Editor/Data/Managed/UnityEditor.dll |
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue