Insanely huge initial commit

This commit is contained in:
2026-02-21 17:04:05 -08:00
parent 9cdd36191a
commit 613d75914a
22525 changed files with 4035207 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
using UnityEngine;
namespace Com.LuisPedroFonseca.ProCamera2D.Platformer
{
[RequireComponent(typeof(CharacterController))]
public class PlayerInput : MonoBehaviour
{
public Transform Body;
// Player Handling
public float gravity = 20;
public float runSpeed = 12;
public float acceleration = 30;
public float jumpHeight = 12;
public int jumpsAllowed = 2;
private float currentSpeed;
private Vector3 amountToMove;
int totalJumps;
CharacterController _characterController;
void Start()
{
_characterController = GetComponent<CharacterController>();
}
void Update()
{
// Reset acceleration upon collision
if ((_characterController.collisionFlags & CollisionFlags.Sides) != 0)
{
currentSpeed = 0;
}
// If player is touching the ground
if ((_characterController.collisionFlags & CollisionFlags.Below) != 0)
{
amountToMove.y = -1f;
totalJumps = 0;
}
else
{
amountToMove.y -= gravity * Time.deltaTime;
}
// Jump
if ((Input.GetKeyDown(KeyCode.W) ||
Input.GetKeyDown(KeyCode.Space) ||
Input.GetKeyDown(KeyCode.UpArrow))
&& totalJumps < jumpsAllowed)
{
totalJumps++;
amountToMove.y = jumpHeight;
}
// Input
var targetSpeed = Input.GetAxis("Horizontal") * runSpeed;
currentSpeed = IncrementTowards(currentSpeed, targetSpeed, acceleration);
// Reset z
if (transform.position.z != 0)
{
amountToMove.z = -transform.position.z;
}
// Set amount to move
amountToMove.x = currentSpeed;
if(amountToMove.x != 0)
Body.localScale = new Vector2(Mathf.Sign(amountToMove.x) * Mathf.Abs(Body.localScale.x), Body.localScale.y);
_characterController.Move(amountToMove * Time.deltaTime);
}
// Increase n towards target by speed
private float IncrementTowards(float n, float target, float a)
{
if (n == target)
{
return n;
}
else
{
float dir = Mathf.Sign(target - n);
n += a * Time.deltaTime * dir;
return (dir == Mathf.Sign(target - n)) ? n : target;
}
}
}
}

View File

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

View File

@@ -0,0 +1,117 @@
using UnityEngine;
using System.Collections;
namespace Com.LuisPedroFonseca.ProCamera2D.Platformer
{
[RequireComponent(typeof(CharacterController))]
public class PlayerInputBot : MonoBehaviour
{
public Transform Body;
// Player Handling
public float gravity = 20;
public float runSpeed = 12;
public float acceleration = 30;
public float jumpHeight = 12;
public int jumpsAllowed = 2;
private float currentSpeed;
private Vector3 amountToMove;
int totalJumps;
bool _fakeInputJump;
float _fakeInputHorizontalAxis;
CharacterController _characterController;
void Start()
{
_characterController = GetComponent<CharacterController>();
StartCoroutine(RandomInputJump());
StartCoroutine(RandomInputSpeed());
}
IEnumerator RandomInputJump()
{
var waitForEndOfFrame = new WaitForEndOfFrame();
while (true)
{
_fakeInputJump = true;
yield return waitForEndOfFrame;
yield return waitForEndOfFrame;
_fakeInputJump = false;
yield return new WaitForSeconds(Random.Range(.2f, 1f));
}
}
IEnumerator RandomInputSpeed()
{
while (true)
{
_fakeInputHorizontalAxis = Random.Range(-1f, 1f);
yield return new WaitForSeconds(Random.Range(1f, 3f));
}
}
void Update()
{
// Reset acceleration upon collision
if ((_characterController.collisionFlags & CollisionFlags.Sides) != 0)
{
currentSpeed = 0;
}
// If player is touching the ground
if ((_characterController.collisionFlags & CollisionFlags.Below) != 0)
{
amountToMove.y = -1f;
totalJumps = 0;
}
else
{
amountToMove.y -= gravity * Time.deltaTime;
}
// Jump
if (_fakeInputJump && totalJumps < jumpsAllowed)
{
totalJumps++;
amountToMove.y = jumpHeight;
}
// Input
var targetSpeed = _fakeInputHorizontalAxis * runSpeed;
currentSpeed = IncrementTowards(currentSpeed, targetSpeed, acceleration);
// Reset z
if(transform.position.z != 0)
{
amountToMove.z = -transform.position.z;
}
// Set amount to move
amountToMove.x = currentSpeed;
if(amountToMove.x != 0)
Body.localScale = new Vector2(Mathf.Sign(amountToMove.x), 1);
_characterController.Move(amountToMove * Time.deltaTime);
}
// Increase n towards target by speed
private float IncrementTowards(float n, float target, float a)
{
if (n == target)
{
return n;
}
else
{
float dir = Mathf.Sign(target - n);
n += a * Time.deltaTime * dir;
return (dir == Mathf.Sign(target - n)) ? n : target;
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 591f7e47384a84b1b8c46d50437c1d4d
timeCreated: 1434304080
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: