// Activate the hitbox with the given parameters public bool startHitbox(List <Vector3> posOffsetIn, List <Quaternion> rotationIn, List <Vector3> sizeIn, List <float> timersIn, int numStatesIn, string moveNameIn) { // Trail Renderer clubTrailRenderer.SetActive(true); // If a hitbox is already active, return if (_state == ColliderState.Open || _state == ColliderState.Colliding || _state == ColliderState.Inactive) { return(false); } //Reset the index hitboxIndex = 0; hitboxNumStates = numStatesIn; //Set hitbox shape and relative position hitboxSizeList = sizeIn; hitboxRotOffset = rotationIn; hitboxPosOffset = posOffsetIn; //Set hitbox timer hitboxTimer = timersIn; //Set name of triggering move moveName = moveNameIn; _state = ColliderState.Open; return(true); }
public static ColliderState SaveColliderState(GameObject forObject) { Collider selectedObjectCollider = forObject.GetComponent <Collider>(); Transform selectedTransform = forObject.transform; ColliderState colliderState = new ColliderState(); if (selectedObjectCollider) { if (selectedObjectCollider is BoxCollider) { colliderState.center = selectedTransform.TransformPoint(((BoxCollider)selectedObjectCollider).center); colliderState.type = ColliderType.BoxCollider; } else if (selectedObjectCollider is CapsuleCollider) { colliderState.center = selectedTransform.TransformPoint(((CapsuleCollider)selectedObjectCollider).center); colliderState.type = ColliderType.CapsuleCollider; } else if (selectedObjectCollider is SphereCollider) { colliderState.center = selectedTransform.TransformPoint(((SphereCollider)selectedObjectCollider).center); colliderState.type = ColliderType.SphereCollider; } else if (selectedObjectCollider is MeshCollider) { colliderState.type = ColliderType.MeshCollider; //colliderState.center = selectedTransform.TransformPoint(((MeshCollider)selectedObjectCollider).bounds.center); } } return(colliderState); }
public Collider[] UpdateHitBox() { if (currentState == ColliderState.Closed || !gameObject.activeInHierarchy) { return(null); } hits = null; switch (shape) { case HitboxShape.Box: hits = Physics.OverlapBox(customPivot.position, new Vector3(boxSize.x * transform.lossyScale.x, boxSize.y * transform.lossyScale.y, boxSize.z * transform.lossyScale.z) / 2, customPivot.rotation, whatToHit); break; case HitboxShape.Sphere: hits = Physics.OverlapSphere(customPivot.position, sphereRadius, whatToHit); break; default: break; } currentState = hits.Length > 0 ? ColliderState.Colliding : ColliderState.Open; return(hits); }
public void HitboxUpdate(LayerMask customLayer) { if (currentState != ColliderState.Closed) { Collider2D[] colliders; if (!useCircle) { colliders = Physics2D.OverlapBoxAll(transform.position, boxSize, transform.eulerAngles.z, customLayer); } else { colliders = Physics2D.OverlapCircleAll(transform.position, radius, customLayer); } for (int i = 0; i < colliders.Length; i++) { if (responder != null) { responder.CollideWith(colliders[i]); } } currentState = colliders.Length > 0 ? ColliderState.Colliding : ColliderState.Open; } }
// Called when hitbox deactivated public void endHitbox() { // Trail Renderer clubTrailRenderer.SetActive(false); //Reset Hitbox Size hitboxSize = new Vector3(0.1f, 0.1f, 0.1f); hitboxRotation = transform.rotation; hitboxPosition = transform.position; //Reset dynamic hitbox counter hitboxIndex = 0; hitboxNumStates = 0; //Reset input matrices hitboxSizeList = new List <Vector3>() { new Vector3(0.1f, 0.1f, 0.1f) }; hitboxRotOffset = new List <Quaternion>() { Quaternion.identity }; hitboxPosOffset = new List <Vector3>() { Vector3.zero }; hitboxTimer = new List <float>() { 0f }; _state = ColliderState.Closed; }
protected void SetCollider(ColliderState state) { var shouldUseHitCollider = state == ColliderState.SHELL; _defaultCollider.gameObject.SetActive(!shouldUseHitCollider); _hitCollider.gameObject.SetActive(shouldUseHitCollider); }
public void AddCollider(ICollider collider) { ColliderState state = new ColliderState(); state.Collider = collider; state.LastPosition = collider.Position; states.Add(state); }
public CustomCollider2D(Entity entity, CustomAABB aABB) { mEntity = entity; mAABB = aABB; mState = ColliderState.Open; mAreas = new List <Vector2i>(); mIdsInAreas = new List <int>(); }
protected virtual bool OpenHitBox() { _state = ColliderState.Open; //Debug.Log("OPEN HITBOX"); EnableHitbox(true); _blackboard.activeHitboxComponents = GetActiveHitboxComponents(); return(true); }
public /// <summary> Restore the collider orientation.</summary> static void RestoreColliderState(GameObject forObject, ColliderState colliderState) { Collider selectedObjectCollider = forObject.GetComponent <Collider>(); Transform selectedTransform = forObject.transform; if (selectedObjectCollider) { if (selectedObjectCollider is BoxCollider) { if (colliderState.type == ColliderType.BoxCollider) { ((BoxCollider)selectedObjectCollider).center = selectedTransform.InverseTransformPoint(colliderState.center); } } else if (selectedObjectCollider is CapsuleCollider) { if (colliderState.type == ColliderType.CapsuleCollider) { ((CapsuleCollider)selectedObjectCollider).center = selectedTransform.InverseTransformPoint(colliderState.center); } } else if (selectedObjectCollider is SphereCollider) { if (colliderState.type == ColliderType.SphereCollider) { ((SphereCollider)selectedObjectCollider).center = selectedTransform.InverseTransformPoint(colliderState.center); } } else if (selectedObjectCollider is MeshCollider) { /* * MeshCollider meshColl = (MeshCollider)selectedObjectCollider; * * bool isConvex = meshColl.convex; * * meshColl.convex = false; * * meshColl.sharedMesh = selectedObjectMesh; * * if (isConvex) * { * * if (selectedObjectMesh.vertexCount >= 2000) * { * * Debug.Log("<b><i><color=#008000ff> PLEASE WAIT... while the convex property on the mesh collider does some calculations.The editor won't be usable until the MeshCollider finishes its calculations.</color></i></b>"); * new UtilityServices().RunAfter(() => { meshColl.convex = true; }, new WaitForSeconds(0.2f)); * } * * else { meshColl.convex = true; } * * } */ } } }
public override void OnInspectorGUI() { BeginInspector(); if (mChildList == null) { SetupChildList(); } m_ColliderState = GetColliderState(); switch (m_ColliderState) { case ColliderState.ColliderOnParent: case ColliderState.ColliderOnAllChildren: break; case ColliderState.NoCollider: EditorGUILayout.HelpBox( "ClearShot requires a Collider extension to rank the shots. Either add one to the ClearShot itself, or to each of the child cameras.", MessageType.Warning); break; case ColliderState.ColliderOnSomeChildren: EditorGUILayout.HelpBox( "Some child cameras do not have a Collider extension. ClearShot requires a Collider on all the child cameras, or alternatively on the ClearShot iself.", MessageType.Warning); break; case ColliderState.ColliderOnChildrenAndParent: EditorGUILayout.HelpBox( "There is a Collider extention on the ClearShot camera, and also on some of its child cameras. You can't have both.", MessageType.Error); break; } DrawHeaderInInspector(); DrawPropertyInInspector(FindProperty(x => x.m_Priority)); DrawTargetsInInspector(FindProperty(x => x.m_Follow), FindProperty(x => x.m_LookAt)); DrawRemainingPropertiesInInspector(); // Blends m_BlendsEditor.DrawEditorCombo( "Create New Blender Asset", Target.gameObject.name + " Blends", "asset", string.Empty, "Custom Blends", false); // vcam children EditorGUILayout.Separator(); EditorGUI.BeginChangeCheck(); mChildList.DoLayoutList(); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } // Extensions DrawExtensionsWidgetInInspector(); }
void Awake() { rg = GetComponent <Rigidbody>(); inventory.SetActive(false); placeholder = selection.transform.GetChild(0).GetChild(0); placeholderCollider = placeholder.GetComponent <ColliderState>(); selectionController = selection.GetComponent <SelectionController>(); circuitController = circuit.GetComponent <CircuitController>(); defaultOriginLocalPosition = selectionController.placeholderOrigin.transform.localPosition; }
public void SetState(ColliderState newState) { m_curState = newState; if (isLocal) { (m_collider as CharacterController).height = m_maxHeight * HeightMultipliers[(int)m_curState]; } else { (m_collider as CapsuleCollider).height = m_maxHeight * HeightMultipliers[(int)m_curState]; } }
public void hitboxUpdate() { if (_state == ColliderState.Closed) { return; } Collider2D[] colliders = Physics2D.OverlapBoxAll(transform.position, hitboxSize, 0, mask); for (int i = 0; i < colliders.Length; i++) { Collider2D aCollider = colliders[i]; _responder?.collisionedWith(aCollider); } _state = colliders.Length > 0 ? ColliderState.Colliding : ColliderState.Open; stopCheckingCollision(); }
public void hitboxUpdate() { // if (state == ColliderState.Closed) { return; } Collider2D[] colliders = Physics2D.OverlapBoxAll(transform.position + offset, halfExtent * 2, transform.rotation.y, layerMask); for (int i = 0; i < colliders.Length; i++) { Collider2D aCollider = colliders[i]; // Make sure you are not hitting yourself if (aCollider.transform.parent != transform.parent) { responder?.collisionedWith(aCollider); } } state = colliders.Length > 0 ? ColliderState.Colliding : ColliderState.Open; }
private void Check() { if (_state == ColliderState.Closed) { return; } Collider[] colliders = UnityEngine.Physics.OverlapBox(transform.position, hitboxSize, transform.rotation, mask); if (colliders.Length > 0) { _state = ColliderState.Colliding; // We should do something with the colliders } else { _state = ColliderState.Open; } }
public void CheckCollision() { if (state == ColliderState.CLOSED) { return; } Collider2D[] colliders = new Collider2D[maxTargets]; int collisions = Physics2D.OverlapBox((Vector2)trans.position + offset, size, 0f, mask, colliders); for (int i = 0; i < collisions; i++) { Collider2D coll = colliders[i]; if (responder != null) { responder.Hit(coll, act); } } state = collisions > 0 ? ColliderState.COLLIDING : ColliderState.OPEN; }
private void Update() { if (state == ColliderState.Closed) { return; } Collider2D[] coll; if (useSphere) { coll = Physics2D.OverlapCircleAll(transform.position, radius, HitBoxMasks); } else { coll = Physics2D.OverlapBoxAll(transform.position, hitboxSize, 0, HitBoxMasks); } if (coll.Length > 0) { //Change the state of the collider when collisions where detected state = ColliderState.Colliding; //Work bacwards through the list to remove the collider //Working backward through the list ensures us that we do not delete an entry infront and crash the loop while trying to access an entry that does not exist anymore. for (int i = coll.Length - 1; i >= 0; i--) { DamageEvent damageEventInfo = new DamageEvent(); damageEventInfo.eventName = "damageEvent"; //Since the hitbox is a child of the attacker object we need to return the parent object to the event system damageEventInfo.baseGO = transform.parent.gameObject; damageEventInfo.targetGO = coll[i].gameObject; damageEventInfo.FireEvent(); } //We stop checking the colision so we dont register the hit anymore stopCheckingCollision(); } else { state = ColliderState.Open; } }
public void stopCheckingCollision() { _state = ColliderState.Closed; }
void ResetState() { state = ColliderState.Open; }
public void startCheckingCollision() { _state = ColliderState.Open; }
void OnCollisionEnter(Collision c) { State = ColliderState.Enter; listener.SendMessage("OnCollisionEnter_" + name,c,SendMessageOptions.DontRequireReceiver); }
public void GetHitBy(int damage) { state = ColliderState.Colliding; Invoke("ResetState", 0.2f); }
public void OpenCollision() { currentState = ColliderState.Open; }
public void CloseCollision() { currentState = ColliderState.Closed; }
void OnTriggerEnter2D(Collider2D c) { State = ColliderState.Enter; listener.SendMessage("OnTriggerEnter2D_" + name,c,SendMessageOptions.DontRequireReceiver); }
void OnCollisionStay2D(Collision2D c) { State = ColliderState.Stay; listener.SendMessage("OnCollisionStay2D_" + name,c,SendMessageOptions.DontRequireReceiver); }
public void StateHit() { state = ColliderState.Hit; }
public void StateNotHit() { state = ColliderState.NotHit; }
void OnTriggerExit(Collider c) { State = ColliderState.Exit; listener.SendMessage("OnTriggerExit_" + name,c,SendMessageOptions.DontRequireReceiver); }
void Start() { state = ColliderState.CLOSED; }
private void Update() { if (_state == ColliderState.Closed) { endHitbox(); return; } playerOrientation = transform.GetComponent <PlayerManager>().getPlayerOrientation(); //Update Hitbox location and orientation to follow player hitboxPosition = transform.position + Quaternion.Euler(0, (float)playerOrientation, 0) * hitboxPosOffset[hitboxIndex]; hitboxRotation = Quaternion.Euler(0, (float)playerOrientation, 0) * hitboxRotOffset[hitboxIndex]; hitboxSize = hitboxSizeList[hitboxIndex]; //Decrement move up-time timer hitboxTimer[hitboxIndex] = hitboxTimer[hitboxIndex] - Time.deltaTime; //Check for collision Collider[] colliders = Physics.OverlapBox(hitboxPosition, hitboxSize, hitboxRotation, LayerMask.GetMask("Hurtbox")); if (colliders.Length == 0) { _state = ColliderState.Open; } foreach (Collider c in colliders) { //Do not count collisions with yourself if (c.transform.root == transform) { continue; } //FIXME: for now, just apply knock back, will compartmentalize this later if (_state == ColliderState.Colliding) { _state = ColliderState.Inactive; } else { _state = ColliderState.Colliding; } if (_responder != null && _state == ColliderState.Colliding) { _responder.collisionedWith(c, moveName); } //FIXME: This is what you're going to need to change if you want 1 hitbox to affect more than one person // c.transform.root.GetComponent<Player>().hitStunTimer = 1f; // c.transform.root.GetComponent<Rigidbody>().AddForce(new Vector3(30, 30, 0)); } //Check if move is finished if (hitboxTimer[hitboxIndex] <= 0f) { //Out of hitboxes, this move is done if (hitboxIndex >= hitboxNumStates - 1) { endHitbox(); } //Still more hitboxes, make sure each hitbox hits only once else { hitboxIndex++; if (_state == ColliderState.Inactive) { _state = ColliderState.Open; } } } }
public void StartCheckingCollision() { state = ColliderState.OPEN; }
public void StopCheckingCollision() { state = ColliderState.CLOSED; }