Projectile trouble with hitting ram

so my projectiles are having real problems trying to hit the ram. even if they are legitamately right in front of them they just arent registering hits often. maybe like 10 percent of the time. i have increased the speed of the projectiles, the range and even increased the size of the box collider of the ram but the hits arent really registering. i also placed the rams to have 1hp starting just so it only takes 1 hit to kill to see if they are registering just not being hit enough. none of this has worked can someone help me out i can post the code in the response just wanna see if anyone can figure it out without the code maybe its something in the editor itself i need to fix

Hi felixq,

Do the particles ‘live’ long enough to hit the enemies? Is ‘Send Collision Message’ enabled in the Collision module of the ParticleSystem(s)? And is the OnParticleCollision method spelt correctly in your code? Look the correct spelling up in the Unity API.

Since you asked whether you should post your code: The answer is almost always ‘yes, please share your code’. You don’t have to ask for permission. If the problem might be in the code, share the relevant code. Then other people will be able to take a look at it if necessary. If you don’t share any code, people will very likely ask, and you will see their answer, then you post the code, and maybe the same or other people will reply. As you can probably imagine, this whole process takes a lot of time. If you share relevant information in your initial post, you’ll increase the chance to get a solution fast. :slight_smile:


See also:

the lifespan of a particle is 2 seconds so should be long enough. collision message is enabled. and onparticlecollision is spelled right. the parenthesis with it is gameobject other so idk if that needs to change. and my enemyhealth code looks like this

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(Enemy))]
public class EnemyHealth : MonoBehaviour
{
[SerializeField] int maxHitPoints = 5;

[Tooltip("Adds the amount to maxhp after enemy dies")]
[SerializeField] int difficultyRamp = 1;
 int currentHitPoints = 0;

Enemy enemy;

void OnEnable()
{
    currentHitPoints = maxHitPoints;
}

private void Start()
{
    enemy = GetComponent<Enemy>();
}

void OnParticleCollision(GameObject other)
{
    ProcessHit();
}

void ProcessHit()
{
    currentHitPoints--;
    if (currentHitPoints <= 0)
    {
        gameObject.SetActive(false);
        maxHitPoints += difficultyRamp;
        enemy.RewardGold();

    }
}

}

i just figured it out nina there were 2 box colliders on my ram. the mesh had one and the parent object had one. i resized the mesh one but the parent one was still really small and only at the bottom of the gameobject. after resizing that one it fixed the problem. i noticed this before but forgot to change it. the projectiles are hitting the target exactly how they should be now

Fantastic! I’m glad it’s finally working. :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms