Throwing Knife Added
This commit is contained in:
@@ -51,7 +51,7 @@ namespace BITFALL.Throws
|
||||
{
|
||||
isHolding = false;
|
||||
base.Entry();
|
||||
animator.Play(BITConstant.Player.Draw);
|
||||
animator.Play(BITConstant.Player.Draw);
|
||||
}
|
||||
|
||||
private void OnThrow(InputAction.CallbackContext obj)
|
||||
@@ -82,6 +82,7 @@ namespace BITFALL.Throws
|
||||
if (!_equipmentContainer.TryUseEquip<EquipmentAsThrow>()) return;
|
||||
var instance = _assetableThrow.GetInstance();
|
||||
if (!instance.TryGetComponent<Rigidbody>(out var _rigidbody)) return;
|
||||
_rigidbody.rotation = throwPoint.rotation;
|
||||
_rigidbody.position = throwPoint.position;
|
||||
_rigidbody.AddForce(throwPoint.forward * throwForce, ForceMode.VelocityChange);
|
||||
}
|
||||
|
52
Assets/Artists/Scripts/Props/Prop_ReplaceOnSleep.cs
Normal file
52
Assets/Artists/Scripts/Props/Prop_ReplaceOnSleep.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITKit;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations;
|
||||
|
||||
namespace BITFALL.Props
|
||||
{
|
||||
public class Prop_ReplaceOnSleep : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Transform prefab;
|
||||
[SerializeField] private new Rigidbody rigidbody;
|
||||
private readonly IntervalUpdate _interval = new(0.16f);
|
||||
private Collider _collider;
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (rigidbody.IsSleeping() && _interval.AllowUpdate)
|
||||
{
|
||||
ReplaceImmediate(_collider.transform);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReplaceImmediate(Transform root=null)
|
||||
{
|
||||
var _transform = transform;
|
||||
var instance = Instantiate(prefab);
|
||||
instance.SetPositionAndRotation(_transform.position, _transform.rotation);
|
||||
|
||||
if (root is not null)
|
||||
{
|
||||
instance.SetParentConstraint(root);
|
||||
if (instance.TryGetComponent<Rigidbody>(out var _rigidbody))
|
||||
{
|
||||
//_rigidbody.isKinematic = true;
|
||||
_rigidbody.isKinematic = true;
|
||||
}
|
||||
}
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision other)
|
||||
{
|
||||
_collider = other.collider;
|
||||
}
|
||||
|
||||
private void OnCollisionStay(Collision other)
|
||||
{
|
||||
_collider = other.collider;
|
||||
}
|
||||
}
|
||||
}
|
57
Assets/Artists/Scripts/Props/Prop_Throw.cs
Normal file
57
Assets/Artists/Scripts/Props/Prop_Throw.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user