Skip to content

Instantly share code, notes, and snippets.

@PappaBjorn
Created February 4, 2020 12:37
Show Gist options
  • Save PappaBjorn/61fbf14bd160a01f601666c514f0b06e to your computer and use it in GitHub Desktop.
Save PappaBjorn/61fbf14bd160a01f601666c514f0b06e to your computer and use it in GitHub Desktop.
Movement-, navigation-, and other controllers/components for the character in Owlchemist
using System.Collections.Generic;
using UnityEngine;
public class CombatComponent : BaseComponent
{
public int damage = 5;
public float projectileSpeed = 2f;
public float hitThreshold = 1f;
public bool isEngagedInCombat { get; set; }
public bool isSwiping { get; set; }
public bool isRunning { get; set; }
public float minDarknessVibrateTime = 1f;
public float maxDarknessVibrateTime = 5f;
public float nextVibrateTime { get; set; }
public float currentVibrateTime { get; set; }
public List<Projectile> projectileList { get; set; }
public Projectile[] projectiles { get; set; }
private Animator animator;
/* InputComponent inputComponent = gameObject.GetComponent<InputComponent>();*/
private void Awake()
{
projectileList = new List<Projectile>();
projectiles = new Projectile[0];
animator = GetComponent<Animator>();
}
public void SetIsEngaged(bool value)
{
isEngagedInCombat = value;
}
// public void IsSwiping(bool isSwiping)
// {
// if (GetComponent<InputComponent>().OnXButtonDown)
// {
//
// }
// }
}
public class Projectile
{
public Projectile(HealthComponent target,Vector3 currentPosition, Vector3 targetPosition, int damage, float speed)
{
this.target = target;
this.currentPosition = currentPosition;
startPosition = currentPosition;
this.targetPosition = targetPosition;
this.damage = damage;
this.speed = speed;
lerpAlpha = 0;
}
public void IncreaseAlpha(float t)
{
lerpAlpha += t;
}
public HealthComponent target;
public Vector3 currentPosition;
public Vector3 startPosition;
public Vector3 targetPosition;
public float lerpAlpha;
public int damage;
public float speed;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
[RequireComponent(typeof(NavMeshAgent))]
public class MovementComponent : BaseComponent
{
public NavMeshAgent agent { get; set; }
public float walkSpeed = .9f;
public float runSpeed = 3f;
public float turnSpeed = .1f;
public bool useAcceleration = true;
public float lerpThreshold = .2f;
public float accelerationSpeed = 1.5f;
public bool alive = true;
public bool movementAllowed { get; set; }
public float blendAlpha { get; set; }
public Vector3 velocity { get; set; }
private void Awake()
{
agent = GetComponent<NavMeshAgent>();
agent.speed = walkSpeed;
movementAllowed = true;
}
public void SetMovementAllowed(bool value)
{
movementAllowed = value;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class NavMeshComponent : BaseComponent
{
public GameObject surfaceObject;
public float distanceThreshold = 3f;
[HideInInspector]
public NavMeshSurface surface;
public delegate void UpdateNavMeshDelegate();
public UpdateNavMeshDelegate OnUpdateNavMesh;
public void Awake()
{
surface = surfaceObject.GetComponent<NavMeshSurface>();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TorchSwipe : MonoBehaviour
{
private Animator animator;
public Collider torchCollider;
//public InputComponent inputComponent;
[SerializeField]
public bool attacking;
void Start()
{
animator = GetComponent<Animator>();
torchCollider = GetComponent<Collider>();
//InputComponent inputComponent = gameObject.GetComponentInParent<InputComponent>();
attacking = false;
// if (inputComponent == null)
// return;
/*SetupInputComponent();*/
}
void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
PerformTorchSwipe();
if (torchCollider.enabled)
attacking = true;
}
else
attacking = false;
}
// public override void SetupInputComponent(InputComponent inputComponent)
// {
// inputComponent.OnXButtonDown += PerformTorchSwipe();
// }
public void PerformTorchSwipe()
{
Debug.Log(this.name + " attack!");
animator.SetTrigger("SwipeAttack");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment