• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Ze_Bomba97 · May 29, 2018 at 02:49 PM · game

Can't damage the enemies or boxes in the 3D Game Kit

I can't damage the enemies or even destroy the destructible boxes, they all are on the enemy layer and i have the enemy layer selected as targel layer on the staff, but it just goes right through them.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by anthot4 · May 29, 2018 at 02:51 PM

Proberly because of how you have adjusted the physics collision matrix. https://docs.unity3d.com/Manual/LayerBasedCollision.html Make all the layers are ticked for the ones you want to collide with the other layers. If this is not the case, I need more information to help you solve the problem.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ze_Bomba97 · May 29, 2018 at 03:01 PM 0
Share

![alt text][1]

This is how my physics collision matrix is, i don't know if this is right i'm really new to unity, so if you could help me out with this i would appreciate it. [1]: /storage/temp/117868-capturar.png

capturar.png (38.2 kB)
avatar image anthot4 Ze_Bomba97 · May 29, 2018 at 03:10 PM 0
Share

Ummm, could you show me your code where you are trying to damage the enemies or destroy the boxes, that would help a lot.

avatar image Ze_Bomba97 anthot4 · May 29, 2018 at 08:15 PM 0
Share

For some reason i'm not able post it here, i get some type of error, but its from the 3D Game $$anonymous$$it made by unity downloaded from the asset store, i didn't write any of it.

avatar image
0

Answer by Ze_Bomba97 · May 30, 2018 at 06:23 AM

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 namespace Gamekit3D
 {
     public class MeleeWeapon : MonoBehaviour
     {
         public int damage = 1;
 
         [System.Serializable]
         public class AttackPoint
         {
             public float radius;
             public Vector3 offset;
             public Transform attackRoot;
 
 #if UNITY_EDITOR
             //editor only as it's only used in editor to display the path of the attack that is used by the raycast
             [NonSerialized] public List<Vector3> previousPositions = new List<Vector3>();
 #endif
 
         }
 
         public ParticleSystem hitParticlePrefab;
         public LayerMask targetLayers;
 
         public AttackPoint[] attackPoints = new AttackPoint[0];
 
         public TimeEffect[] effects;
 
         [Header("Audio")] public RandomAudioPlayer hitAudio;
         public RandomAudioPlayer attackAudio;
 
         public bool throwingHit
         {
             get { return m_IsThrowingHit; }
             set { m_IsThrowingHit = value; }
         }
 
         protected GameObject m_Owner;
 
         protected Vector3[] m_PreviousPos = null;
         protected Vector3 m_Direction;
 
         protected bool m_IsThrowingHit = false;
         protected bool m_InAttack = false;
 
         const int PARTICLE_COUNT = 10;
         protected ParticleSystem[] m_ParticlesPool = new ParticleSystem[PARTICLE_COUNT];
         protected int m_CurrentParticle = 0;
 
         protected static RaycastHit[] s_RaycastHitCache = new RaycastHit[32];
         protected static Collider[] s_ColliderCache = new Collider[32];
 
         private void Awake()
         {
             if (hitParticlePrefab != null)
             {
                 for (int i = 0; i < PARTICLE_COUNT; ++i)
                 {
                     m_ParticlesPool[i] = Instantiate(hitParticlePrefab);
                     m_ParticlesPool[i].Stop();
                 }
             }
         }
 
         private void OnEnable()
         {
 
         }
 
         //whoever own the weapon is responsible for calling that. Allow to avoid "self harm"
         public void SetOwner(GameObject owner)
         {
             m_Owner = owner;
         }
 
         public void BeginAttack(bool thowingAttack)
         {
             if (attackAudio != null)
                 attackAudio.PlayRandomClip();
             throwingHit = thowingAttack;
 
             m_InAttack = true;
 
             m_PreviousPos = new Vector3[attackPoints.Length];
 
             for (int i = 0; i < attackPoints.Length; ++i)
             {
                 Vector3 worldPos = attackPoints[i].attackRoot.position +
                                    attackPoints[i].attackRoot.TransformVector(attackPoints[i].offset);
                 m_PreviousPos[i] = worldPos;
 
 #if UNITY_EDITOR
                 attackPoints[i].previousPositions.Clear();
                 attackPoints[i].previousPositions.Add(m_PreviousPos[i]);
 #endif
             }
         }
 
         public void EndAttack()
         {
             m_InAttack = false;
 
 
 #if UNITY_EDITOR
             for (int i = 0; i < attackPoints.Length; ++i)
             {
                 attackPoints[i].previousPositions.Clear();
             }
 #endif
         }
 
         private void FixedUpdate()
         {
             if (m_InAttack)
             {
                 for (int i = 0; i < attackPoints.Length; ++i)
                 {
                     AttackPoint pts = attackPoints[i];
 
                     Vector3 worldPos = pts.attackRoot.position + pts.attackRoot.TransformVector(pts.offset);
                     Vector3 attackVector = worldPos - m_PreviousPos[i];
 
                     if (attackVector.magnitude < 0.001f)
                     {
                         // A zero vector for the sphere cast don't yield any result, even if a collider overlap the "sphere" created by radius. 
                         // so we set a very tiny microscopic forward cast to be sure it will catch anything overlaping that "stationary" sphere cast
                         attackVector = Vector3.forward * 0.0001f;
                     }
 
 
                     Ray r = new Ray(worldPos, attackVector.normalized);
 
                     int contacts = Physics.SphereCastNonAlloc(r, pts.radius, s_RaycastHitCache, attackVector.magnitude,
                         ~0,
                         QueryTriggerInteraction.Ignore);
 
                     for (int k = 0; k < contacts; ++k)
                     {
                         Collider col = s_RaycastHitCache[k].collider;
 
                         if (col != null)
                             CheckDamage(col, pts);
                     }
 
                     m_PreviousPos[i] = worldPos;
 
 #if UNITY_EDITOR
                     pts.previousPositions.Add(m_PreviousPos[i]);
 #endif
                 }
             }
         }
 
         private bool CheckDamage(Collider other, AttackPoint pts)
         {
             Damageable d = other.GetComponent<Damageable>();
             if (d == null)
             {
                 return false;
             }
 
             if (d.gameObject == m_Owner)
                 return true; //ignore self harm, but do not end the attack (we don't "bounce" off ourselves)
 
             if ((targetLayers.value & (1 << other.gameObject.layer)) == 0)
             {
                 //hit an object that is not in our layer, this end the attack. we "bounce" off it
                 return false;
             }
 
             if (hitAudio != null)
             {
                 var renderer = other.GetComponent<Renderer>();
                 if (!renderer)
                     renderer = other.GetComponentInChildren<Renderer> ();
                 if (renderer)
                     hitAudio.PlayRandomClip (renderer.sharedMaterial);
                 else
                     hitAudio.PlayRandomClip ();
             }
 
             Damageable.DamageMessage data;
 
             data.amount = damage;
             data.damager = this;
             data.direction = m_Direction.normalized;
             data.damageSource = m_Owner.transform.position;
             data.throwing = m_IsThrowingHit;
             data.stopCamera = false;
 
             d.ApplyDamage(data);
 
             if (hitParticlePrefab != null)
             {
                 m_ParticlesPool[m_CurrentParticle].transform.position = pts.attackRoot.transform.position;
                 m_ParticlesPool[m_CurrentParticle].time = 0;
                 m_ParticlesPool[m_CurrentParticle].Play();
                 m_CurrentParticle = (m_CurrentParticle + 1) % PARTICLE_COUNT;
             }
 
             return true;
         }
 
 #if UNITY_EDITOR
 
         private void OnDrawGizmosSelected()
         {
             for (int i = 0; i < attackPoints.Length; ++i)
             {
                 AttackPoint pts = attackPoints[i];
 
                 if (pts.attackRoot != null)
                 {
                     Vector3 worldPos = pts.attackRoot.TransformVector(pts.offset);
                     Gizmos.color = new Color(1.0f, 1.0f, 1.0f, 0.4f);
                     Gizmos.DrawSphere(pts.attackRoot.position + worldPos, pts.radius);
                 }
 
                 if (pts.previousPositions.Count > 1)
                 {
                     UnityEditor.Handles.DrawAAPolyLine(10, pts.previousPositions.ToArray());
                 }
             }
         }
 
 #endif
     }
 }
















using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using Gamekit3D.Message; using UnityEngine.Serialization;

 namespace Gamekit3D
 {
     public partial class Damageable : MonoBehaviour
     {
 
         public int maxHitPoints;
         [Tooltip("Time that this gameObject is invulnerable for, after receiving damage.")]
         public float invulnerabiltyTime;
 
 
         [Tooltip("The angle from the which that damageable is hitable. Always in the world XZ plane, with the forward being rotate by hitForwardRoation")]
         [Range(0.0f, 360.0f)]
         public float hitAngle = 360.0f;
         [Tooltip("Allow to rotate the world forward vector of the damageable used to define the hitAngle zone")]
         [Range(0.0f, 360.0f)]
         [FormerlySerializedAs("hitForwardRoation")] //SHAME!
         public float hitForwardRotation = 360.0f;
 
         public bool isInvulnerable { get; set; }
         public int currentHitPoints { get; private set; }
 
         public UnityEvent OnDeath, OnReceiveDamage, OnHitWhileInvulnerable, OnBecomeVulnerable, OnResetDamage;
 
         [Tooltip("When this gameObject is damaged, these other gameObjects are notified.")]
         [EnforceType(typeof(Message.IMessageReceiver))]
         public List<MonoBehaviour> onDamageMessageReceivers;
 
         protected float m_timeSinceLastHit = 0.0f;
         protected Collider m_Collider;
 
         System.Action schedule;
 
         void Start()
         {
             ResetDamage();
             m_Collider = GetComponent<Collider>();
         }
 
         void Update()
         {
             if (isInvulnerable)
             {
                 m_timeSinceLastHit += Time.deltaTime;
                 if (m_timeSinceLastHit > invulnerabiltyTime)
                 {
                     m_timeSinceLastHit = 0.0f;
                     isInvulnerable = false;
                     OnBecomeVulnerable.Invoke();
                 }
             }
         }
 
         public void ResetDamage()
         {
             currentHitPoints = maxHitPoints;
             isInvulnerable = false;
             m_timeSinceLastHit = 0.0f;
             OnResetDamage.Invoke();
         }
 
         public void SetColliderState(bool enabled)
         {
             m_Collider.enabled = enabled;
         }
 
         public void ApplyDamage(DamageMessage data)
         {
             if (currentHitPoints <= 0)
             {//ignore damage if already dead. TODO : may have to change that if we want to detect hit on death...
                 return;
             }
 
             if (isInvulnerable)
             {
                 OnHitWhileInvulnerable.Invoke();
                 return;
             }
 
             Vector3 forward = transform.forward;
             forward = Quaternion.AngleAxis(hitForwardRotation, transform.up) * forward;
 
             //we project the direction to damager to the plane formed by the direction of damage
             Vector3 positionToDamager = data.damageSource - transform.position;
             positionToDamager -= transform.up * Vector3.Dot(transform.up, positionToDamager);
 
             if (Vector3.Angle(forward, positionToDamager) > hitAngle * 0.5f)
                 return;
 
             isInvulnerable = true;
             currentHitPoints -= data.amount;
 
             if (currentHitPoints <= 0)
                 schedule += OnDeath.Invoke; //This avoid race condition when objects kill each other.
             else
                 OnReceiveDamage.Invoke();
 
             var messageType = currentHitPoints <= 0 ? MessageType.DEAD : MessageType.DAMAGED;
 
             for (var i = 0; i < onDamageMessageReceivers.Count; ++i)
             {
                 var receiver = onDamageMessageReceivers[i] as IMessageReceiver;
                 receiver.OnReceiveMessage(messageType, this, data);
             }
         }
 
         void LateUpdate()
         {
             if (schedule != null)
             {
                 schedule();
                 schedule = null;
             }
         }
 
 #if UNITY_EDITOR
         private void OnDrawGizmosSelected()
         {
             Vector3 forward = transform.forward;
             forward = Quaternion.AngleAxis(hitForwardRotation, transform.up) * forward;
 
             if (Event.current.type == EventType.Repaint)
             {
                 UnityEditor.Handles.color = Color.blue;
                 UnityEditor.Handles.ArrowHandleCap(0, transform.position, Quaternion.LookRotation(forward), 1.0f,
                     EventType.Repaint);
             }
 
 
             UnityEditor.Handles.color = new Color(1.0f, 0.0f, 0.0f, 0.5f);
             forward = Quaternion.AngleAxis(-hitAngle * 0.5f, transform.up) * forward;
             UnityEditor.Handles.DrawSolidArc(transform.position, transform.up, forward, hitAngle, 1.0f);
         }
 #endif
     }
 
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Rod_Info · May 29, 2018 at 08:56 PM

Olá, boa tarde!

Eu não entendi muito bem seu problema. Mas, verifique se as camadas do projeto estão tendo conexão, independentemente se as caixas "possuem" colisão normal ou trigger. Para checar se existe colisão entre os "gameobjects ", verifique no menu Edit - > Project Settings -> Physics (para 3D) ou Physics (para 2D)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ze_Bomba97 · May 29, 2018 at 11:14 PM 0
Share

![alt text][1]

Olá é a isto que se está a referir? [1]: /storage/temp/117895-capturar.png

capturar.png (38.1 kB)
avatar image
0

Answer by fcanerdogan · Nov 15, 2020 at 08:38 AM

Hey, @Ze_Bomba97 did you find any solutions to this question? I'm having the exact same problem right now and it is very frustrating.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

119 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

getting udp package info inside unity (GlovePIE) 0 Answers

how do you put the slenderman in unity3d 0 Answers

Horror Game AI script recommendation? 1 Answer

how to select an object in game mode ? 1 Answer

Rotating a camera when RMB is held down. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges