Throwing Knife Added

This commit is contained in:
CortexCore
2023-10-25 17:26:42 +08:00
parent 3e39e627bc
commit c5f638d9d2
31 changed files with 2432 additions and 310 deletions

View File

@@ -0,0 +1,57 @@
using System;
using System.Collections;
using System.Collections.Generic;
using BITKit;
using BITKit.Entities;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace BITFALL.Props
{
public class Prop_Throw : MonoBehaviour
{
[SerializeField] private new Rigidbody rigidbody;
[SerializeField] private int damage;
[SerializeField] private int force;
[SerializeField] private LayerMask layerMask;
private void FixedUpdate()
{
if (Physics.Linecast(rigidbody.position, rigidbody.position + rigidbody.velocity * Time.fixedDeltaTime,
out var hit,
layerMask
))
{
var _rigidbody = hit.rigidbody;
if(hit.collider.transform.TryGetComponent<IDamagable>(out var damagable))
{
damagable.GiveDamage(new DamageMessage()
{
Target = damagable.Entity,
Damage = damage,
Location = new Location()
{
position = hit.point,
rotation = Quaternion.LookRotation(hit.normal),
forward = hit.normal,
}
});
if(damagable.Rigidbody is not null)
{
_rigidbody = damagable.Rigidbody;
}
}
if (_rigidbody)
{
_rigidbody.AddForceAtPositionAsync((hit.point-rigidbody.position).normalized * force, hit.point, ForceMode.Impulse).Forget();
}
rigidbody.Sleep();
if (TryGetComponent<Prop_ReplaceOnSleep>(out var replace))
{
replace.ReplaceImmediate(hit.collider.transform);
}
}
}
}
}