Closed Niinra closed 7 months ago
I will fix it
Try replace DamageInfoExtensions
to
using UnityEngine;
namespace MultiplayerARPG
{
public static class DamageInfoExtensions
{
public static void GetDamagePositionAndRotation(this IDamageInfo damageInfo, BaseCharacterEntity attacker, bool isLeftHand, AimPosition aimPosition, Vector3 stagger, out Vector3 position, out Vector3 direction, out Quaternion rotation)
{
if (GameInstance.Singleton.DimensionType == DimensionType.Dimension2D)
{
Transform damageTransform = damageInfo.GetDamageTransform(attacker, isLeftHand);
position = damageTransform.position;
GetDamageRotation2D(attacker.Direction2D, out rotation);
direction = attacker.Direction2D;
#if UNITY_EDITOR
attacker.SetDebugDamage(position, direction, rotation, isLeftHand);
#endif
return;
}
if (aimPosition.type == AimPositionType.Direction)
{
position = aimPosition.position;
rotation = Quaternion.Euler(Quaternion.LookRotation(aimPosition.direction).eulerAngles + stagger);
direction = rotation * Vector3.forward;
}
else
{
// NOTE: Allow aim position type `None` here, may change it later
Transform damageTransform = damageInfo.GetDamageTransform(attacker, isLeftHand);
position = damageTransform.position;
GetDamageRotation3D(attacker.transform.forward, position, aimPosition.position, stagger, out rotation);
direction = rotation * Vector3.forward;
}
#if UNITY_EDITOR
attacker.SetDebugDamage(position, direction, rotation, isLeftHand);
#endif
}
public static void GetDamageRotation2D(Vector2 aimDirection, out Quaternion rotation)
{
rotation = Quaternion.Euler(0, 0, (Mathf.Atan2(aimDirection.y, aimDirection.x) * (180 / Mathf.PI)) + 90);
}
public static void GetDamageRotation3D(Vector3 entityForward, Vector3 origin, Vector3 target, Vector3 stagger, out Quaternion rotation)
{
Vector3 direction = target - origin;
if (Vector3.Dot(entityForward, direction) < 0.5f)
{
// Not in front of character, so set direction to character forward
direction = entityForward;
}
rotation = Quaternion.Euler(Quaternion.LookRotation(direction).eulerAngles + stagger);
}
}
}
It fixed a little, but it still happens when you are too close, example video:https://imgur.com/0AejcdT
Hmm, try add log message to GetDamageRotation3D
function, I want to see a value of Vector3.Dot(entityForward, direction)
, entityForward
, target
, origin
and direction
when it is having issues
Hmm, try add log message to GetDamageRotation3D function, I want to see a value of Vector3.Dot(entityForward, direction), entityForward, target, origin and direction when it is having issues`
Ehm, I don't know if what you were asking for was this debug in this method because I was able to translate but it doesn't show anything. I don't know if I misunderstood you, but it leaves nothing in the console and there was no different behavior, it's still the same despite the change code
Yes, do like that it has nothing shown?
No, it doesn't throw anything
Try change codes in ShooterPlayerCharacterController
-> IsInFront
function to
public virtual bool IsInFront(Vector3 target)
{
return Vector3.Dot(_cameraForward, target - EntityTransform.position) > 0.5f;
}
using UnityEngine;
namespace MultiplayerARPG
{
public static class DamageInfoExtensions
{
public static void GetDamagePositionAndRotation(this IDamageInfo damageInfo, BaseCharacterEntity attacker, bool isLeftHand, AimPosition aimPosition, Vector3 stagger, out Vector3 position, out Vector3 direction, out Quaternion rotation)
{
if (GameInstance.Singleton.DimensionType == DimensionType.Dimension2D)
{
Transform damageTransform = damageInfo.GetDamageTransform(attacker, isLeftHand);
position = damageTransform.position;
GetDamageRotation2D(attacker.Direction2D, out rotation);
direction = attacker.Direction2D;
#if UNITY_EDITOR
attacker.SetDebugDamage(position, direction, rotation, isLeftHand);
#endif
return;
}
if (aimPosition.type == AimPositionType.Direction)
{
position = aimPosition.position;
rotation = Quaternion.Euler(Quaternion.LookRotation(aimPosition.direction).eulerAngles + stagger);
direction = rotation * Vector3.forward;
if (attacker.IsOwnerClient)
{
Debug.LogError("here " + position + " " + direction + " " + Vector3.Dot(attacker.EntityTransform.forward, direction));
}
}
else
{
// NOTE: Allow aim position type `None` here, may change it later
Transform damageTransform = damageInfo.GetDamageTransform(attacker, isLeftHand);
position = damageTransform.position;
GetDamageRotation3D(attacker.transform.forward, position, aimPosition.position, stagger, out rotation);
direction = rotation * Vector3.forward;
if (attacker.IsOwnerClient)
{
Debug.LogError("here2 " + position + " " + direction + " " + Vector3.Dot(attacker.EntityTransform.forward, direction));
}
}
#if UNITY_EDITOR
attacker.SetDebugDamage(position, direction, rotation, isLeftHand);
#endif
}
public static void GetDamageRotation2D(Vector2 aimDirection, out Quaternion rotation)
{
rotation = Quaternion.Euler(0, 0, (Mathf.Atan2(aimDirection.y, aimDirection.x) * (180 / Mathf.PI)) + 90);
}
public static void GetDamageRotation3D(Vector3 entityForward, Vector3 origin, Vector3 target, Vector3 stagger, out Quaternion rotation)
{
Vector3 direction = target - origin;
if (Vector3.Dot(entityForward, direction) < 0.5f)
{
// Not in front of character, so set direction to character forward
direction = entityForward;
}
rotation = Quaternion.Euler(Quaternion.LookRotation(direction).eulerAngles + stagger);
}
}
}
Tell me the value when the problem is occurring.
Don't do anything yet, I am currently have time to try it and fix it, I will tell you when it was fixed.
Okay, try this, change codes in ShooterPlayerCharacterController
-> IsInFront
function to
public virtual bool IsInFront(Vector3 target)
{
// Get aim position direction
AimPosition aimPosition = PlayingCharacterEntity.GetAttackAimPosition(ref _isLeftHandAttacking, target);
switch (aimPosition.type)
{
case AimPositionType.Direction:
// Check that the direction is in front of character or not
return Vector3.Dot(aimPosition.direction, EntityTransform.forward) > 0.5f;
}
// 2D mode?
return true;
}
Or this
public virtual bool IsInFront(Vector3 target)
{
// Get aim position direction
AimPosition aimPosition = PlayingCharacterEntity.GetAttackAimPosition(ref _isLeftHandAttacking, target);
switch (aimPosition.type)
{
case AimPositionType.Direction:
// Check that the direction is in front of character or not
return Vector3.Angle(aimPosition.direction, EntityTransform.forward) < 115f;
}
// 2D mode?
return true;
}
Reopen if it is not working :)
There is a problem when you are very close to a target and you point it towards the enemy. Look for the enemy and this error happens with the projectiles. If you are very close, they somehow try to find the target and this happens in an example video:https://imgur.com/gHwiSkr
The solution that I see possible is to deactivate the auto-targeting when the character is too close, of course if this is possible obviously