Browse Source

COLLISION SHIT FINALLY WORKING WOOO

next:

-Find collision contact point.
master
Marquitos 10 years ago
parent
commit
f744a744b7
  1. BIN
      New Unity Project/Assets/Materials/Ground.mat
  2. 8
      New Unity Project/Assets/Materials/Ground.mat.meta
  3. 4
      New Unity Project/Assets/Models.meta
  4. BIN
      New Unity Project/Assets/Models/BasicCube.blend
  5. 78
      New Unity Project/Assets/Models/BasicCube.blend.meta
  6. BIN
      New Unity Project/Assets/Models/BasicCube.blend1
  7. 8
      New Unity Project/Assets/Models/BasicCube.blend1.meta
  8. 9
      New Unity Project/Assets/Models/Materials.meta
  9. BIN
      New Unity Project/Assets/Models/Materials/Material.mat
  10. 8
      New Unity Project/Assets/Models/Materials/Material.mat.meta
  11. 58
      New Unity Project/Assets/Scripts/CharacterController/CECollider.cs
  12. 40
      New Unity Project/Assets/Scripts/CharacterController/CECollision.cs
  13. 21
      New Unity Project/Assets/Scripts/CharacterController/CEController.cs
  14. 7
      New Unity Project/Assets/Scripts/CharacterController/CEPrimitives.cs
  15. 31
      New Unity Project/Assets/Scripts/CharacterController/test.cs
  16. 4
      New Unity Project/Assets/Scripts/CharacterController/test.cs.meta
  17. 204
      New Unity Project/Assets/Scripts/Forces/Force.cs
  18. 12
      New Unity Project/Assets/Scripts/Forces/Force.cs.meta
  19. 93
      New Unity Project/Assets/Scripts/Forces/ForceController.cs
  20. 12
      New Unity Project/Assets/Scripts/Forces/ForceController.cs.meta
  21. 63
      New Unity Project/Assets/Scripts/Forces/ForceStruct.cs
  22. 12
      New Unity Project/Assets/Scripts/Forces/ForceStruct.cs.meta
  23. 79
      New Unity Project/Assets/Scripts/Player.cs
  24. BIN
      New Unity Project/Assets/_Scenes/Minigame.unity
  25. BIN
      New Unity Project/Assets/_Scenes/Test2.unity
  26. 8
      New Unity Project/Assets/_Scenes/Test2.unity.meta
  27. BIN
      New Unity Project/Library/CurrentLayout.dwlt
  28. BIN
      New Unity Project/Library/InspectorExpandedItems.asset
  29. BIN
      New Unity Project/Library/ScriptAssemblies/Assembly-CSharp.dll
  30. BIN
      New Unity Project/Library/ScriptAssemblies/Assembly-CSharp.dll.mdb
  31. BIN
      New Unity Project/Library/ShaderCache/0/023605c1129e91a84feafb375851d6d8.bin
  32. BIN
      New Unity Project/Library/ShaderCache/1/1a90f4326711054b4a1681a657e6a4d0.bin
  33. BIN
      New Unity Project/Library/ShaderCache/6/61b14d94ff1a4ed54936e4c0d9535c8c.bin
  34. BIN
      New Unity Project/Library/ShaderCache/7/7d2335f9ab588c012a54f58e8ffcd8a5.bin
  35. BIN
      New Unity Project/Library/ShaderCache/a/a94d9c0c3dc0d33f95d784ddeabc10b3.bin
  36. BIN
      New Unity Project/Library/ShaderCache/a/aa00539aa653743b0ab8d37278e7099d.bin
  37. BIN
      New Unity Project/Library/ShaderCache/a/ac469a81b907afb81d6c5b3487654ef8.bin
  38. BIN
      New Unity Project/Library/ShaderCache/c/cb1ac00288dbfda92dd6ae9f9b962c63.bin
  39. BIN
      New Unity Project/Library/ShaderCache/d/d574ba999252fbd42555e7b56b133aa0.bin
  40. BIN
      New Unity Project/Library/ShaderCache/e/e551ba3d60f05ae8920c288b86dc717d.bin
  41. BIN
      New Unity Project/Library/ShaderCache/e/edb483df9f6607d79740246e18f8babb.bin
  42. BIN
      New Unity Project/Library/ShaderCache/f/f39fb01f0cdd1a1bfea2396190f6ca90.bin
  43. BIN
      New Unity Project/Library/assetDatabase3
  44. BIN
      New Unity Project/Library/expandedItems
  45. BIN
      New Unity Project/Library/metadata/00/00000000000000002000000000000000
  46. BIN
      New Unity Project/Library/metadata/00/00000000000000004000000000000000
  47. BIN
      New Unity Project/Library/metadata/00/00000000000000006100000000000000
  48. BIN
      New Unity Project/Library/metadata/09/092e42aed3ea51d49b61711bd48284fe
  49. BIN
      New Unity Project/Library/metadata/09/092e42aed3ea51d49b61711bd48284fe.info
  50. BIN
      New Unity Project/Library/metadata/0e/0e35b01539b765e439f694ed7e8a7022
  51. BIN
      New Unity Project/Library/metadata/11/114545d266452cb4b96fd2ef86902650
  52. BIN
      New Unity Project/Library/metadata/11/114545d266452cb4b96fd2ef86902650.info
  53. BIN
      New Unity Project/Library/metadata/16/16a8185af630ffa4fadff4fdb168e89a
  54. BIN
      New Unity Project/Library/metadata/1a/1ab5a05df27fed64291f5d2341f929b7
  55. BIN
      New Unity Project/Library/metadata/1a/1ab5a05df27fed64291f5d2341f929b7.info
  56. BIN
      New Unity Project/Library/metadata/2f/2f6cb937bd9326148b7ab27db4d1d775
  57. BIN
      New Unity Project/Library/metadata/34/348109b22797c724282c6d7807b00b73
  58. BIN
      New Unity Project/Library/metadata/3f/3f7585d4a547a6e4191719736d0daf78
  59. BIN
      New Unity Project/Library/metadata/3f/3f7585d4a547a6e4191719736d0daf78.info
  60. BIN
      New Unity Project/Library/metadata/4d/4dec4b65dcbaa4440ad5eaa237496cda
  61. BIN
      New Unity Project/Library/metadata/57/57b436089801943408c989af783a9a85
  62. BIN
      New Unity Project/Library/metadata/60/60d552ec687c4b145a91814cb030cb35
  63. BIN
      New Unity Project/Library/metadata/60/60d552ec687c4b145a91814cb030cb35.info
  64. BIN
      New Unity Project/Library/metadata/7a/7a07c3efc56913144be618cb56ec5107
  65. BIN
      New Unity Project/Library/metadata/7a/7a07c3efc56913144be618cb56ec5107.info
  66. BIN
      New Unity Project/Library/metadata/81/81aea943a0d329749bef1a54a294d002
  67. BIN
      New Unity Project/Library/metadata/e1/e180352f7114a4b4fab550f64fd9271a
  68. BIN
      New Unity Project/Library/metadata/e1/e180352f7114a4b4fab550f64fd9271a.info
  69. BIN
      New Unity Project/Library/metadata/fa/fa5061d9c09bf974c8583d5e72982fd9
  70. BIN
      New Unity Project/Library/metadata/fa/fa5061d9c09bf974c8583d5e72982fd9.info
  71. BIN
      New Unity Project/Library/metadata/fe/fead40d50297ab84baf2200692cb99a0
  72. BIN
      New Unity Project/Library/metadata/fe/fead40d50297ab84baf2200692cb99a0.info
  73. BIN
      New Unity Project/ProjectSettings/InputManager.asset

BIN
New Unity Project/Assets/Materials/Ground.mat

Binary file not shown.

8
New Unity Project/Assets/Materials/Ground.mat.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3f7585d4a547a6e4191719736d0daf78
timeCreated: 1463417062
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

4
New Unity Project/Assets/Scripts/Forces.meta → New Unity Project/Assets/Models.meta

@ -1,7 +1,7 @@
fileFormatVersion: 2
guid: 713d19245f9f01349b61eade4b876d9b
guid: 1ab5a05df27fed64291f5d2341f929b7
folderAsset: yes
timeCreated: 1463261964
timeCreated: 1463416934
licenseType: Free
DefaultImporter:
userData:

BIN
New Unity Project/Assets/Models/BasicCube.blend

Binary file not shown.

78
New Unity Project/Assets/Models/BasicCube.blend.meta

@ -0,0 +1,78 @@
fileFormatVersion: 2
guid: 092e42aed3ea51d49b61711bd48284fe
timeCreated: 1463416939
licenseType: Free
ModelImporter:
serializedVersion: 19
fileIDToRecycleName:
100000: //RootNode
400000: //RootNode
2300000: //RootNode
3300000: //RootNode
4300000: Cube
7400000: Default Take
9500000: //RootNode
materials:
importMaterials: 0
materialName: 0
materialSearch: 1
animations:
legacyGenerateAnimations: 4
bakeSimulation: 0
resampleRotations: 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: 1
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: 0
copyAvatar: 0
humanDescription:
human: []
skeleton: []
armTwist: 0.5
foreArmTwist: 0.5
upperLegTwist: 0.5
legTwist: 0.5
armStretch: 0.05
legStretch: 0.05
feetSpacing: 0
rootMotionBoneName:
hasTranslationDoF: 0
lastHumanDescriptionAvatarSource: {instanceID: 0}
animationType: 0
humanoidOversampling: 1
additionalBone: 0
userData:
assetBundleName:
assetBundleVariant:

BIN
New Unity Project/Assets/Models/BasicCube.blend1

Binary file not shown.

8
New Unity Project/Assets/Models/BasicCube.blend1.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fead40d50297ab84baf2200692cb99a0
timeCreated: 1463417014
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
New Unity Project/Assets/Models/Materials.meta

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: fa5061d9c09bf974c8583d5e72982fd9
folderAsset: yes
timeCreated: 1463416939
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

BIN
New Unity Project/Assets/Models/Materials/Material.mat

Binary file not shown.

8
New Unity Project/Assets/Models/Materials/Material.mat.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e180352f7114a4b4fab550f64fd9271a
timeCreated: 1463416939
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

58
New Unity Project/Assets/Scripts/CharacterController/CECollider.cs

@ -4,6 +4,38 @@ using System.Collections.Generic;
namespace CharacterEngine.Primitives
{
public class CEProjection
{
public Vector2 axis;
public float max;
public float min;
public CEProjection() { }
public CEProjection (CECollider coll, Vector2 axis)
{
Project(coll, axis);
}
public void Project(CECollider coll, Vector2 axis)
{
for (int i = 0; i < 4; i++)
{
Vector2 p = Vector3.Project(coll.GetPoint(i), axis);
float distance = p.magnitude * Mathf.Sign(Vector2.Dot(p, axis));
if (i == 0)
{
max = min = distance;
}
else
{
if (distance > max) max = distance;
else if (distance < min) min = distance;
}
}
}
}
public class CECollider
{
public static int[,] edges = new int[,]
@ -11,6 +43,11 @@ namespace CharacterEngine.Primitives
{0, 2}, {0, 3}, {1, 2},{1, 3}
};
public static int[,] pointsNeighbours = new int[,]
{
{2, 3}, {3, 2}, {0, 1},{1, 0}
};
private BoxCollider2D collider;
public BoxCollider2D Coll
{
@ -70,22 +107,30 @@ namespace CharacterEngine.Primitives
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public virtual Vector2 GetPoint (int index)
public Vector2 GetPoint (int index)
{
return position + (Vector2)(collider.transform.rotation * Vector2.Scale(localPoints[index], collider.transform.lossyScale));
}
public virtual Vector2 GetPoint(int index, Vector2 position)
public Vector2 GetPoint(int index, Vector2 position)
{
return position + (Vector2)(collider.transform.rotation * Vector2.Scale(localPoints[index], collider.transform.lossyScale));
}
public virtual Vector2 GetAABBPoint(int index)
public Vector2 GetAABBPoint(int index)
{
return position + (Vector2)(Vector2.Scale(localPoints[index], collider.transform.lossyScale));
}
public virtual Vector2 GetAABBPoint(int index, Vector2 position)
public Vector2 GetAABBPoint(int index, Vector2 position)
{
return position + (Vector2)(Vector2.Scale(localPoints[index], collider.transform.lossyScale));
}
public Vector2 GetNormal(int index)
{
return Vector3.Cross(GetPoint(edges[index, 0]) - GetPoint(edges[index, 1]), Vector3.forward).normalized;
}
public Vector2 GetNormal(int index, Vector2 position)
{
return Vector3.Cross(GetPoint(edges[index, 0], position) - GetPoint(edges[index, 1], position), Vector3.forward).normalized;
}
public bool ContainsPoint (Vector2 p)
{
@ -96,6 +141,11 @@ namespace CharacterEngine.Primitives
return insideX && insideY;
}
public void Project(Vector2 normal, Vector2 p)
{
}
/// <summary>
/// Collision test along a path
/// </summary>

40
New Unity Project/Assets/Scripts/CharacterController/CECollision.cs

@ -20,6 +20,37 @@ namespace CharacterEngine.Primitives
{
Vector2 closestPoint = Vector2.zero;
CECollision collision = new CECollision();
///IS NOT MTV THO (music television) is MINIMUN TRANSLATION VECTOR (funny joke uh)
Vector2 MTV = Vector2.zero;
float minimunOverlap = 0.0f;
Vector2[] axes = new Vector2[8];
for (int i = 0; i < 8; i++)
{
axes[i] = i < 4 ? a.GetNormal(i) : b.GetNormal(i - 4);
}
for (int i = 0; i < axes.Length; i++)
{
CEProjection projectionA = new CEProjection(a, axes[i]);
CEProjection projectionB = new CEProjection(b, axes[i]);
float overlapValue = Mathf.Abs(projectionA.max - projectionB.min);
if (i == 0 || overlapValue < minimunOverlap)
{
minimunOverlap = overlapValue;
MTV = axes[i] * minimunOverlap;
}
}
collision.impulse = MTV;
collision.normal = collision.impulse.normalized;
///COULDNT DETRMINE YET HOW TO FIND POINT ILL DO IT ASFASDGSD
collision.point = Vector2.zero;
/*
for (int i = 0; i < 4; i++)
{
Vector2 currentPoint = a.GetPoint(i);
@ -49,9 +80,10 @@ namespace CharacterEngine.Primitives
return collision;
}
}
*/
//IF REACH HERE DIDNT RESOLVE SHIT
Debug.Log("Could not resolve collision");
//Debug.Log("Could not resolve collision");
return collision;
}
@ -88,6 +120,12 @@ namespace CharacterEngine.Primitives
return p + (Vector2)Vector3.Project(distanceToPointA, segmentNormal);
}
public static Vector2 ClosestVectorToPlane(Vector2 p, Vector2 normal, Vector2 position)
{
Vector2 plane = Vector3.Cross(normal, Vector3.forward);
Vector2 distanceToPosition = position - p;
return p + (Vector2)Vector3.Project(distanceToPosition, plane);
}
}
}

21
New Unity Project/Assets/Scripts/CharacterController/CEController.cs

@ -17,6 +17,8 @@ namespace CharacterEngine.Controller
#endregion
protected Vector2 moveVelocity;
private CEPrimitives primitives;
/*Summary:
@ -30,12 +32,6 @@ namespace CharacterEngine.Controller
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
@ -43,15 +39,20 @@ namespace CharacterEngine.Controller
while "Fixed Update" dont.
*/
// Update is called once per frame
void Update()
void FixedUpdate ()
{
MoveStep();
primitives.Step();
}
void MoveStep ()
{
primitives.AddVelocity(moveVelocity);
}
void FixedUpdate ()
public void Move (Vector2 velocity)
{
primitives.Step();
moveVelocity = velocity;
}
}
}

7
New Unity Project/Assets/Scripts/CharacterController/CEPrimitives.cs

@ -59,6 +59,11 @@ namespace CharacterEngine.Primitives
PhysicsStep();
}
public void AddVelocity ( Vector2 velocity )
{
this.velocity += velocity;
}
void PhysicsStep()
{
GetVelocity();
@ -78,7 +83,7 @@ namespace CharacterEngine.Primitives
void GravityStep()
{
velocity.y += gravity * controller.weight * Time.deltaTime * 1.2f;
velocity.x = -gravity * 0.5f;
velocity.x = 10.0f;
}
void CollisionStep()

31
New Unity Project/Assets/Scripts/CharacterController/test.cs

@ -2,21 +2,34 @@
using System.Collections;
using CharacterEngine.Primitives;
public class test : MonoBehaviour {
public class Test : MonoBehaviour {
public BoxCollider2D coll;
protected CECollider ce;
public Transform a;
public Transform b;
public BoxCollider2D c;
public BoxCollider2D c1;
public BoxCollider2D c2;
private CECollider cec;
private CECollider cec1;
private CECollider cec2;
// Use this for initialization
void Start () {
ce = new CECollider(coll);
cec = new CECollider(c);
cec1 = new CECollider(c1);
cec2 = new CECollider(c2);
}
// Update is called once per frame
void Update () {
if (ce.ContainsPoint(transform.position))
{
Vector2 p = CECollision.ClosestPointInBounds(ce, transform.position);
Debug.DrawLine(p, transform.position, Color.red);
}
Vector2 axis = (a.position - b.position).normalized;
CEProjection p = new CEProjection(cec, axis);
CEProjection p1 = new CEProjection(cec1, axis);
CEProjection p2 = new CEProjection(cec2, axis);
Debug.DrawLine(axis * p.min, axis * p.max, Color.red);
Debug.DrawLine(axis * p1.min, axis * p1.max, Color.blue);
Debug.DrawLine(axis * p2.min, axis * p2.max, Color.yellow);
}
}

4
New Unity Project/Assets/Scripts/CharacterController/test.cs.meta

@ -1,6 +1,6 @@
fileFormatVersion: 2
guid: f0ed370640e457f4ca5447af56a3319c
timeCreated: 1463341313
guid: 7a07c3efc56913144be618cb56ec5107
timeCreated: 1463429200
licenseType: Free
MonoImporter:
serializedVersion: 2

204
New Unity Project/Assets/Scripts/Forces/Force.cs

@ -1,204 +0,0 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Forces
{
public class Force : System.Object
{
public ForceProps properties;
protected Vector2 goal_vector = Vector2.up;
protected Vector2 last_velocity = Vector2.zero;
protected Vector2 init_in = Vector2.zero;
protected Vector2 init_out = Vector2.zero;
protected Vector2 current_output = Vector2.zero;
protected float init_time = 0.0f;
/// <summary>
/// last call from velocity method
/// </summary>
protected float last_step_time = 0.0f;
/// <summary>
/// last call from user (like AddForce) to now when start fading out
/// </summary>
protected float last_call_time = 0.0f;
protected float current_delta_step = 0.0f;
protected float current_delta_call = 0.0f;
protected float current_delta_notCall = 0.0f;
/// <summary>
/// time since init calling
/// </summary>
protected float time_calling = 0.0f;
/// <summary>
/// absolute time since init
/// </summary>
protected float time_stepping = 0.0f;
/// <summary>
/// time since left calling
/// </summary>
protected float time_notCalling = 0.0f;
protected bool killed = false;
public Force(string id, Vector2 target_direction, float target_speed, float inertia_in = 1.0f, float inertia_out = 1.0f, float impulse = 0.0f)
{
properties = new ForceProps(id, target_speed, inertia_in, inertia_out, impulse);
Call(target_direction);
}
public Force(ForceProps props, Vector2 target_direction)
{
properties = props;
Call(target_direction);
}
public Vector2 Velocity()
{
Vector2 delta = Vector2.zero;
Vector2 current_target_velocity = Vector2.zero;
if (init_time == 0.0f) Initialize();
StartStep();
current_target_velocity = FadeIn() + FadeOut();
delta = current_target_velocity;
current_output = Clamp(last_velocity + delta, goal_vector);
EndStep();
return current_output;
}
/// <summary>
/// called by user to add force
/// </summary>
public void Call(Vector2 new_goal_vector)
{
if (properties.forceMode == ForceMode.Impulse)
Initialize();
last_call_time = Time.time;
goal_vector = new_goal_vector.normalized * properties.target_speed;
}
/// <summary>
/// Determines if the force is being used after reaching zero force
/// </summary>
/// <returns></returns>
public bool Using()
{
//Wait half a second to check if the velocity is null
return ((Time.time - last_call_time) < 0.5f || last_velocity != Vector2.zero) && !killed;
}
public void Kill ()
{
last_call_time = 0.0f;
current_delta_call = 0.0f;
current_delta_notCall = 0.0f;
last_velocity = Vector2.zero;
killed = true;
}
/// <summary>
/// Returns the value of the last call
/// </summary>
/// <returns></returns>
public Vector2 LastVelocity()
{
return last_velocity;
}
protected void Initialize()
{
init_time = Time.time;
}
protected void StartStep()
{
///Is the force acting like an impulse? if it is, then stop calling if impulse time < currentTime
bool impulse = (properties.impulse > 0.0f && Time.time - init_time < properties.impulse);
current_delta_step = last_step_time == 0.0f ? 0.0f : Time.time - last_step_time;
if (last_call_time == 0.0f)
{
current_delta_call = 0.0f;
current_delta_notCall = 0.0f;
}
else
{
if (last_step_time - last_call_time > current_delta_step && !impulse)
{
current_delta_notCall = current_delta_step;
///set a start point to fade velocity
init_out = last_velocity;
current_delta_call = 0.0f;
time_calling = 0.0f;
}
else
{
current_delta_call = current_delta_step;
///set a start point to fade velocity
init_in = last_velocity;
current_delta_notCall = 0.0f;
time_notCalling = 0.0f;
}
}
time_calling += current_delta_call;
time_stepping += current_delta_step;
}
protected Vector2 FadeIn()
{
// float fade_in_fact = 0.0f;
Vector2 output = Vector2.zero;
if (current_delta_call <= 0.0f) return Vector2.zero;
//fade_in_fact = Mathf.Clamp01(time_calling / inertia_in);
output = (goal_vector - last_velocity) * (current_delta_call / properties.inertia_in);
return output;
}
protected Vector2 FadeOut()
{
//float fade_out_fact = 0.0f;
Vector2 output = Vector2.zero;
if (current_delta_notCall <= 0.0f) return Vector2.zero;
//fade_out_fact = Mathf.Clamp01(time_notCalling / inertia_in);
output = (Vector2.zero - last_velocity) * (current_delta_notCall / properties.inertia_out);
return output;
}
protected Vector2 Clamp(Vector2 vector, Vector2 max)
{
float max_magnitude = max.magnitude;
float currentMagnitude = vector.magnitude;
float dot = Vector2.Dot(vector, max);
Vector2 output = vector;
//check if it is calling to clamp
if (currentMagnitude > max_magnitude && dot > 0.0f && current_delta_call != 0.0f)
{
output = max;
}
//checl if is not calling to clamp to zero
else if (dot <= 0.0f && current_delta_call == 0.0f)
{
output = Vector2.zero;
}
return output;
}
protected void EndStep()
{
last_step_time = Time.time;
last_velocity = current_output;
}
}
}

12
New Unity Project/Assets/Scripts/Forces/Force.cs.meta

@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 57b436089801943408c989af783a9a85
timeCreated: 1455409843
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

93
New Unity Project/Assets/Scripts/Forces/ForceController.cs

@ -1,93 +0,0 @@
using UnityEngine;
using System.Collections.Generic;
namespace Forces
{
/// <summary>
/// Controls forces to be esay for the user to use
/// </summary>
public class ForceController : System.Object
{
protected Dictionary<string, Force> active_forces = new Dictionary<string, Force>();
protected List<Force2Call> call_forces = new List<Force2Call>();
protected List<string> null_forces_index = new List<string>();
protected Vector2 lastFinalVel;
public void AddForce(ForceProps forceProps, Vector3 direction)
{
Force target = Target(forceProps, direction);
call_forces.Add(new Force2Call(direction, target));
}
public void DestroyForce (ForceProps forceProps)
{
Force f = GetForce(forceProps);
if (f == null) return;
f.Kill();
null_forces_index.Add(forceProps.Name);
}
public Force GetForce(ForceProps force)
{
if (active_forces.ContainsKey(force.Name))
return active_forces[force.Name];
return null;
}
public Vector2 Update()
{
Vector2 final_velocity = Vector2.zero;
///ADD AND CALL STEP
foreach (Force2Call f in call_forces)
{
f.force.Call(f.direction);
}
///APPLY STEP
foreach (string key in active_forces.Keys)
{
Force f = active_forces[key];
///Add to null forces if the force isnt using
if (!f.Using())
{
null_forces_index.Add(f.properties.Name);
continue;
}
Vector2 add = f.Velocity();
final_velocity += add;
}
///CLEAR STEP
foreach (string i in null_forces_index)
{
active_forces.Remove(i);
}
call_forces.Clear();
null_forces_index.Clear();
Vector2 final = final_velocity * Time.deltaTime * 100.0f;
Vector3 out_ = final - lastFinalVel;
lastFinalVel = final;
return out_;
}
protected Force Target(ForceProps force, Vector3 direction)
{
Force out_ = GetForce(force);
if (out_ == null)
{
out_ = new Force(force, direction);
active_forces.Add(out_.properties.Name, out_);
}
return out_;
}
}
}

12
New Unity Project/Assets/Scripts/Forces/ForceController.cs.meta

@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 114545d266452cb4b96fd2ef86902650
timeCreated: 1456794068
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

63
New Unity Project/Assets/Scripts/Forces/ForceStruct.cs

@ -1,63 +0,0 @@
using UnityEngine;
using System.Collections;
namespace Forces
{
public enum ForceMode { Force, Impulse, Aceleration }
/// <summary>
/// Label force static information
/// </summary>
[System.Serializable]
public struct ForceProps
{
/// <summary>
/// indetify instance id
/// </summary>
public string Name;
/// <summary>
/// inertia value when starts in seconds (fade in)
/// </summary>
public float inertia_in;
/// <summary>
/// inertia value when ends in seconds (fade out)
/// </summary>
public float inertia_out;
/// <summary>
/// time calling without Update
/// </summary>
public float impulse;
/// <summary>
/// goal speed
/// </summary>
public float target_speed;
/// <summary>
/// mode of applying this force
/// </summary>
public ForceMode forceMode;
public ForceProps(string Name, float target_speed, float inertia_in = 1.0f, float inertia_out = 1.0f, float impulse = 0.0f)
{
this.Name = Name;
this.target_speed = target_speed;
this.inertia_in = inertia_in;
this.inertia_out = inertia_out;
this.impulse = impulse;
this.forceMode = impulse > 0.0f ? ForceMode.Impulse : ForceMode.Force;
}
}
/// <summary>
/// Target force and new vector to apply
/// </summary>
public struct Force2Call
{
public Vector3 direction;
public Force force;
public Force2Call(Vector3 direction, Force force)
{
this.direction = direction;
this.force = force;
}
}
}

12
New Unity Project/Assets/Scripts/Forces/ForceStruct.cs.meta

@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 2f6cb937bd9326148b7ab27db4d1d775
timeCreated: 1456794126
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

79
New Unity Project/Assets/Scripts/Player.cs

@ -1,25 +1,15 @@
using UnityEngine;
using System.Collections;
using Forces;
using CharacterEngine.Controller;
public class Player : MonoBehaviour {
public float weight = 20.0f;
protected new Collider collider;
protected Rigidbody rigidBody;
protected Vector3 velocity;
protected ForceController controller;
public ForceProps[] forces;
protected CEController controller;
protected bool grounding;
void Awake ()
{
rigidBody = GetComponent<Rigidbody>();
controller = new ForceController();
collider = GetComponent<Collider>();
controller = GetComponent<CEController>();
}
// Use this for initialization
void Start () {
@ -32,73 +22,22 @@ public class Player : MonoBehaviour {
if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0.3f)
{
float value = Mathf.Sign(Input.GetAxis("Horizontal"));
controller.AddForce(forces[0], Vector3.right * value);
controller.Move(Vector3.right * value);
}
/*
if (Input.GetButtonDown("A") && grounding)
{
controller.AddForce(forces[1], Vector3.up);
}
//controller.AddForce(forces[1], Vector3.up);
}
void FixedUpdate ()
{
Step();
*/
}
void OnLanded ()
{
/*
controller.DestroyForce(forces[1]);
velocity.y = 0.0f;
}
void Step ()
{
bool lastGrounded = grounding;
velocity = rigidBody.velocity;
velocity.y += -8.0f * weight * Time.fixedDeltaTime;
Vector2 forceControllerVel = controller.Update();
velocity.x += forceControllerVel.x;
if (controller.GetForce(forces[1]) != null)
{
Debug.Log(forceControllerVel.y);
}
velocity.y += forceControllerVel.y;
grounding = IsGrounded();
if (lastGrounded != grounding)
{
if (grounding) OnLanded();
}
rigidBody.velocity = velocity;
}
bool IsGrounded()
{
Vector3[] raycastPoints =
{
new Vector3(collider.bounds.max.x, collider.bounds.min.y + 0.1f, collider.bounds.center.z),
new Vector3(collider.bounds.min.x, collider.bounds.min.y + 0.1f, collider.bounds.center.z),
new Vector3(collider.bounds.center.x, collider.bounds.min.y + 0.1f, collider.bounds.center.z)
};
for (int i = 0; i < raycastPoints.Length; i++)
{
//Debug.DrawRay(raycastPoints[i], Vector3.down * (0.1f + velocity.magnitude * Time.fixedDeltaTime));
if (Physics.Raycast(raycastPoints[i], Vector3.down, 0.1f + velocity.magnitude * Time.fixedDeltaTime))
{
return true;
}
}
return false;
*/
}
}

BIN
New Unity Project/Assets/_Scenes/Minigame.unity

Binary file not shown.

BIN
New Unity Project/Assets/_Scenes/Test2.unity

Binary file not shown.

8
New Unity Project/Assets/_Scenes/Test2.unity.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 60d552ec687c4b145a91814cb030cb35
timeCreated: 1463417594
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

BIN
New Unity Project/Library/CurrentLayout.dwlt

Binary file not shown.

BIN
New Unity Project/Library/InspectorExpandedItems.asset

Binary file not shown.

BIN
New Unity Project/Library/ScriptAssemblies/Assembly-CSharp.dll

Binary file not shown.

BIN
New Unity Project/Library/ScriptAssemblies/Assembly-CSharp.dll.mdb

Binary file not shown.

BIN
New Unity Project/Library/ShaderCache/0/023605c1129e91a84feafb375851d6d8.bin

Binary file not shown.

BIN
New Unity Project/Library/ShaderCache/1/1a90f4326711054b4a1681a657e6a4d0.bin

Binary file not shown.

BIN
New Unity Project/Library/ShaderCache/6/61b14d94ff1a4ed54936e4c0d9535c8c.bin

Binary file not shown.

BIN
New Unity Project/Library/ShaderCache/7/7d2335f9ab588c012a54f58e8ffcd8a5.bin

Binary file not shown.

BIN
New Unity Project/Library/ShaderCache/a/a94d9c0c3dc0d33f95d784ddeabc10b3.bin

Binary file not shown.

BIN
New Unity Project/Library/ShaderCache/a/aa00539aa653743b0ab8d37278e7099d.bin

Binary file not shown.

BIN
New Unity Project/Library/ShaderCache/a/ac469a81b907afb81d6c5b3487654ef8.bin

Binary file not shown.

BIN
New Unity Project/Library/ShaderCache/c/cb1ac00288dbfda92dd6ae9f9b962c63.bin

Binary file not shown.

BIN
New Unity Project/Library/ShaderCache/d/d574ba999252fbd42555e7b56b133aa0.bin

Binary file not shown.

BIN
New Unity Project/Library/ShaderCache/e/e551ba3d60f05ae8920c288b86dc717d.bin

Binary file not shown.

BIN
New Unity Project/Library/ShaderCache/e/edb483df9f6607d79740246e18f8babb.bin

Binary file not shown.

BIN
New Unity Project/Library/ShaderCache/f/f39fb01f0cdd1a1bfea2396190f6ca90.bin

Binary file not shown.

BIN
New Unity Project/Library/assetDatabase3

Binary file not shown.

BIN
New Unity Project/Library/expandedItems

Binary file not shown.

BIN
New Unity Project/Library/metadata/00/00000000000000002000000000000000

Binary file not shown.

BIN
New Unity Project/Library/metadata/00/00000000000000004000000000000000

Binary file not shown.

BIN
New Unity Project/Library/metadata/00/00000000000000006100000000000000

Binary file not shown.

BIN
New Unity Project/Library/metadata/09/092e42aed3ea51d49b61711bd48284fe

Binary file not shown.

BIN
New Unity Project/Library/metadata/09/092e42aed3ea51d49b61711bd48284fe.info

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
New Unity Project/Library/metadata/0e/0e35b01539b765e439f694ed7e8a7022

Binary file not shown.

BIN
New Unity Project/Library/metadata/11/114545d266452cb4b96fd2ef86902650

Binary file not shown.

BIN
New Unity Project/Library/metadata/11/114545d266452cb4b96fd2ef86902650.info

Binary file not shown.

BIN
New Unity Project/Library/metadata/16/16a8185af630ffa4fadff4fdb168e89a

Binary file not shown.

BIN
New Unity Project/Library/metadata/1a/1ab5a05df27fed64291f5d2341f929b7

Binary file not shown.

BIN
New Unity Project/Library/metadata/71/713d19245f9f01349b61eade4b876d9b.info → New Unity Project/Library/metadata/1a/1ab5a05df27fed64291f5d2341f929b7.info

Binary file not shown.

BIN
New Unity Project/Library/metadata/2f/2f6cb937bd9326148b7ab27db4d1d775

Binary file not shown.

BIN
New Unity Project/Library/metadata/34/348109b22797c724282c6d7807b00b73

Binary file not shown.

BIN
New Unity Project/Library/metadata/3f/3f7585d4a547a6e4191719736d0daf78

Binary file not shown.

BIN
New Unity Project/Library/metadata/3f/3f7585d4a547a6e4191719736d0daf78.info

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
New Unity Project/Library/metadata/4d/4dec4b65dcbaa4440ad5eaa237496cda

Binary file not shown.

BIN
New Unity Project/Library/metadata/57/57b436089801943408c989af783a9a85

Binary file not shown.

BIN
New Unity Project/Library/metadata/60/60d552ec687c4b145a91814cb030cb35

Binary file not shown.

BIN
New Unity Project/Library/metadata/f0/f0ed370640e457f4ca5447af56a3319c.info → New Unity Project/Library/metadata/60/60d552ec687c4b145a91814cb030cb35.info

Binary file not shown.

BIN
New Unity Project/Library/metadata/f0/f0ed370640e457f4ca5447af56a3319c → New Unity Project/Library/metadata/7a/7a07c3efc56913144be618cb56ec5107

Binary file not shown.

BIN
New Unity Project/Library/metadata/57/57b436089801943408c989af783a9a85.info → New Unity Project/Library/metadata/7a/7a07c3efc56913144be618cb56ec5107.info

Binary file not shown.

BIN
New Unity Project/Library/metadata/81/81aea943a0d329749bef1a54a294d002

Binary file not shown.

BIN
New Unity Project/Library/metadata/e1/e180352f7114a4b4fab550f64fd9271a

Binary file not shown.

BIN
New Unity Project/Library/metadata/e1/e180352f7114a4b4fab550f64fd9271a.info

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
New Unity Project/Library/metadata/71/713d19245f9f01349b61eade4b876d9b → New Unity Project/Library/metadata/fa/fa5061d9c09bf974c8583d5e72982fd9

Binary file not shown.

BIN
New Unity Project/Library/metadata/2f/2f6cb937bd9326148b7ab27db4d1d775.info → New Unity Project/Library/metadata/fa/fa5061d9c09bf974c8583d5e72982fd9.info

Binary file not shown.

BIN
New Unity Project/Library/metadata/fe/fead40d50297ab84baf2200692cb99a0

Binary file not shown.

BIN
New Unity Project/Library/metadata/fe/fead40d50297ab84baf2200692cb99a0.info

Binary file not shown.

BIN
New Unity Project/ProjectSettings/InputManager.asset

Binary file not shown.
Loading…
Cancel
Save