Initial Commit

This commit is contained in:
Simeon Radivoev 2022-02-12 12:53:50 +02:00
commit ee5c2f922d
Signed by: simeonradivoev
GPG key ID: 7611A451D2A5D37A
2255 changed files with 547750 additions and 0 deletions

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 799f16bd8e6ffdc4da235a74245333ce
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,59 @@
using UnityEngine;
using System.Collections;
namespace Polycrime
{
public static class TrajectoryLine
{
public static void Render(Vector3 startPoint, Vector3 endPoint, float time, Color color)
{
Vector3 initialVelocity = TrajectoryMath.CalculateVelocity(startPoint, endPoint, time);
float deltaTime = time / initialVelocity.magnitude;
int drawSteps = (int)(initialVelocity.magnitude - 0.5f)+1;
Vector3 currentPosition = startPoint;
Vector3 previousPosition = currentPosition;
Gizmos.color = color;
if (IsParabolicVelocity(initialVelocity))
{
for (int i = 0; i < drawSteps; i++)
{
currentPosition += (initialVelocity * deltaTime) + (0.5f * Physics.gravity * deltaTime * deltaTime);
initialVelocity += Physics.gravity * deltaTime;
Gizmos.DrawLine(previousPosition, currentPosition);
//////////////////////////////////////////////////////////////////////////////////
// If the next loop is the last iteration, then don't update the previous position
// vector so it can be used to draw the gizmos arrow.
if ((i + 1) < drawSteps)
{
previousPosition = currentPosition;
}
}
DrawArrow(previousPosition, (currentPosition - previousPosition));
}
else
{
Vector3 newUpDirection = new Vector3(currentPosition.x, endPoint.y, currentPosition.z);
Gizmos.DrawLine(currentPosition, newUpDirection);
DrawArrow(newUpDirection, new Vector3(0f, 0.01f, 0f));
}
}
private static void DrawArrow(Vector3 position, Vector3 direction)
{
int[] arrowAngles = new int[] { 225, 135 };
foreach (int angle in arrowAngles)
{
Vector3 endPoint = Quaternion.LookRotation(direction) * Quaternion.Euler(0, angle, 0) * Vector3.forward;
Gizmos.DrawRay(position + direction, endPoint * 0.5f);
}
}
private static bool IsParabolicVelocity(Vector3 velocity)
{
return !(velocity.x == 0 && velocity.z == 0);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f8a4af99ac684b848a46f48319b8538b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,52 @@
using UnityEngine;
using System.Collections;
namespace Polycrime
{
public static class TrajectoryMath
{
private static float verticalOnlyMin = 0.1f;
public static Vector2 CalculateVelocity(Vector2 startPoint, Vector2 endPoint, float time)
{
return CalculateVelocity(startPoint, endPoint, time, 1);
}
////////////////////////////////////////////////////////////////////////////////////
// If the target is far enough away, the normal trajectory is calculated based on
// the editor's set gravity. A non-parabolic trajectory is calculated if the target
// is almost straight overhead. The verticalOnlyMin can be adjusted to when the
// velocity calculation should switch to vertical populsion only.
public static Vector2 CalculateVelocity(Vector2 startPoint, Vector2 endPoint, float time,float gravityMultiply)
{
Vector3 direction = (endPoint - startPoint);
float gravity = Physics.gravity.magnitude * gravityMultiply;
float yVelocity = (direction.y / time) + (0.5f * gravity * time);
if (TargetTooClose(startPoint, endPoint))
{
return new Vector3(0, yVelocity, 0);
}
else
{
return new Vector3(direction.x / time, yVelocity, direction.z / time);
}
}
public static Vector2 CalculateVelocityWithHeight(Vector2 startPoint, Vector2 endPoint, float maxHeight, float gravityMultiply)
{
float gravity = Physics2D.gravity.y * gravityMultiply;
Vector2 direction = (endPoint - startPoint);
var time = Mathf.Sqrt(-2 * maxHeight / gravity) + Mathf.Sqrt(2 * (direction.y - maxHeight) / gravity);
return new Vector2(direction.x / time,Mathf.Sqrt(-2 * gravity * maxHeight));
}
private static bool TargetTooClose(Vector3 startPoint, Vector3 endPoint)
{
Vector3 targetPosition = endPoint;
Vector3 leveledTarget = new Vector3(targetPosition.x, startPoint.y, targetPosition.z);
return Vector3.Distance(leveledTarget, startPoint) <= verticalOnlyMin;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cc1a1bc69cfe6d7428150b41616debb2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: