Heyhey, i got this raycast script:
using UnityEngine;
using System.Collections;
using RootMotion.Dynamics;
namespace RootMotion.Demos {
public class RaycastShooter : MonoBehaviour {
public LayerMask layers;
public float unpin = 10f;
public float force = 10f;
public ParticleSystem blood;
public Vector3 offset;
[SerializeField] private bool m_ShowDebugRay; // Optionally show the debug ray.
[SerializeField] private float m_DebugRayLength = 5f; // Debug ray length.
[SerializeField] private float m_DebugRayDuration = 1f; // How long the Debug ray will remain visible.
[SerializeField] private float m_RayLength = 500f; // How far into the scene the ray is cast.
// Update is called once per frame
void Update () {
if (m_ShowDebugRay)
{
Debug.DrawRay(transform.position + offset, transform.forward * m_DebugRayLength, Color.blue, m_DebugRayDuration);
Ray ray = new Ray (transform.position + offset , transform.forward);
// Raycast to find a ragdoll collider
RaycastHit hit = new RaycastHit();
if (Physics.Raycast(ray, out hit, 100f, layers)) {
Debug.DrawRay(transform.position, transform.forward * m_DebugRayLength, Color.red, m_DebugRayDuration);
}
}
if (Input.GetMouseButtonDown(0)) {
//Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Ray ray = new Ray (transform.position, transform.forward);
// Raycast to find a ragdoll collider
RaycastHit hit = new RaycastHit();
if (Physics.Raycast(ray, out hit, 100f, layers)) {
var broadcaster = hit.collider.attachedRigidbody.GetComponent<MuscleCollisionBroadcaster>();
if (broadcaster != null) {
broadcaster.Hit(unpin, ray.direction * force, hit.point);
blood.transform.position = hit.point;
blood.transform.rotation = Quaternion.LookRotation(-ray.direction);
blood.Emit(5);
}
}
}
}
}
}
how can i ignore all children of the parent where the raycast script is in?
the important parts of the script are after “if (Input.GetMouseButtonDown(0)) {”
so my character layer is layer 9 and the weapon where the ray got shot is inside this character object.
iam using a complicated ragdoll physics character controller. so that leads sometimes to the case, that the character shoot itself. so both, enemy and my character are on the layer 9. so how can i do it that the ray still hits everything on layer 9, but not the one where it is inside?
btw, the objects/weapon which shoots the ray can be droped. so it can be picked up by every character in the scene again after its dropped. so a fixed gameobject that should be ignored doesent work here.