Hello to all sry for the disturb but i have stargne issue , when the enemy unit has dead in theory the Ragdool do is fuction but in my case when the enemy is dead the enemy spawn another dead, and of course similar issue affect the playerunit body,look for the image for anry suggestion or advice
First of all, are you getting any errors when the character dies?
Paste in your RagdollSpawner.cs script and we’ll take a look.
- Forum User Guides : How to apply code formatting within your post
No error durind and the exit of Play mode
This is the Script you ask:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UnitRagdollSpawner : MonoBehaviour
{
[SerializeField] private Transform ragdollPrefab;
[SerializeField] private Transform originalRootBone;
private HealthSystem healthSystem;
private void Awake()
{
healthSystem = GetComponent<HealthSystem>();
healthSystem.OnDead += HealthSystem_OnDead;
}
private void HealthSystem_OnDead(object sender, EventArgs e)
{
Transform ragdollTransform = Instantiate(ragdollPrefab, transform.position, transform.rotation);
UnitRagdoll unitRagdoll = ragdollTransform.GetComponent<UnitRagdoll>();
unitRagdoll.Setup(originalRootBone);
}
}
The code is correct.
Check your characters to make sure that they don’t have two RagdollSpawners on them.
in the prefab i dont have two RagdollSpawners, i use the grade option for kill the enemy in the test and it very strange one prefab appears every time i use this option insted of the shoot action, maybe is a problem of the assets i use because before they work correclty
Am I understanding that this is only happening during the Grenade action rather than Shoot action?
Yes thats right, for now i dont impemet the sword action or other for now
I’m not entirely sure what would be different about the two actions that could cause this…
Paste in your GrenadeProjectile.cs
this is the script you Aksed sry for the delay but i fell asleep and go to bed
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GrenadeProjectile : MonoBehaviour
{
public static event EventHandler OnAnyGrenadeExploded;
[SerializeField] private Transform grenadeExplodeVFXPrefab;
[SerializeField] private TrailRenderer trailRenderer;
[SerializeField] private AnimationCurve arcYAnimationCurve;
private Vector3 targetPosition;
private Action onGrenadeBehaviourComplete;
private float totalDistance;
private Vector3 positionXZ;
private void Update()
{
Vector3 moveDir = (targetPosition - positionXZ).normalized;
float moveSpeed = 15f;
positionXZ += moveDir * moveSpeed * Time.deltaTime;
float distance = Vector3.Distance(positionXZ, targetPosition);
float distanceNormalized = 1 - distance / totalDistance;
float maxHeight = totalDistance / 4f;
float positionY = arcYAnimationCurve.Evaluate(distanceNormalized) * maxHeight;
transform.position = new Vector3(positionXZ.x, positionY, positionXZ.z);
float reachedTargetDistance = .2f;
if (Vector3.Distance(positionXZ, targetPosition) < reachedTargetDistance)
{
float damageRadius = 4f;
Collider[] colliderArray = Physics.OverlapSphere(targetPosition, damageRadius);
foreach (Collider collider in colliderArray)
{
if (collider.TryGetComponent<Unit>(out Unit targetUnit))
{
targetUnit.Damage(30);
}
if (collider.TryGetComponent<DestructibleCrate>(out DestructibleCrate destructibleCrate))
{
destructibleCrate.Damage();
}
}
OnAnyGrenadeExploded?.Invoke(this, EventArgs.Empty);
trailRenderer.transform.parent = null;
Instantiate(grenadeExplodeVFXPrefab, targetPosition + Vector3.up * 1f, Quaternion.identity);
Destroy(gameObject);
onGrenadeBehaviourComplete();
}
}
public void Setup(GridPosition targetGridPosition, Action onGrenadeBehaviourComplete)
{
this.onGrenadeBehaviourComplete = onGrenadeBehaviourComplete;
targetPosition = LevelGrid.Instance.GetWorldPosition(targetGridPosition);
positionXZ = transform.position;
positionXZ.y = 0;
totalDistance = Vector3.Distance(positionXZ, targetPosition);
}
}
I’m not seeing anything in this script that would lead to the unit dying twice…
I’ll need to take a closer look at your project.
Zip up your project and upload it to https://gdev.tv/projectupload and I’ll take a look.
Quick update: I have the project, and I will investigate tonight after work.
Ok, looking first at Shoot() and that was causing two ragdolls because it was actually damaging the target twice:
private void Shoot()
{
OnAnyShoot?.Invoke(this, new OnShootEventArgs
{
targetUnit = targetUnit,
shootingUnit = unit
});
targetUnit.Damage(40); //first damage
OnShoot?.Invoke(this, new OnShootEventArgs
{
targetUnit = targetUnit,
shootingUnit = unit
});
targetUnit.Damage(40); //2nd damage
}
The Grenade Action wasn’t causing two Ragdolls.
Removing the 2nd targetUnit.Damage() in ShootAction should fix the issue.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.