// Start is called before the first frame update void Start() { gravity = Physics2D.gravity * gravityScale; standLayerMask = LayerHelper.GetLayerMask(standLayerNames, true); myTrans = transform; coll2D = GetComponent <Collider2D>(); }
void setTeam(TEAM team) { if (team == TEAM.NULL) { Debug.LogWarning("WARNING : TEAM cannot be set to null"); return; } _team = team; foreach (Transform c in GetComponentsInChildren <Transform>()) { if (c.GetComponent <DamagingPoint> () != null) { c.gameObject.layer = LayerHelper.GetAttackBoxLayer(team); c.GetComponent <DamagingPoint> ().SetDamagableLayers(); } if (c.GetComponent <Hitbox> () != null) { c.gameObject.layer = LayerHelper.GetHitboxLayer(team); } } if (GetComponent <CharacterMovementHandler> () != null) { // print ("team : " + team); GetComponent <CharacterMovementHandler> ().SetLayerMask(LayerHelper.GetLayerMask(team)); } }
Vector3 getWorldPoint(Vector3 screenPoint) { RaycastHit h; Physics.Raycast(getRay(screenPoint), out h, Mathf.Infinity, LayerHelper.GetLayerMask(hitOnlyLayers)); return(h.point); }
void removeTouch(Touch t) { RaycastHit h = new RaycastHit(); bool hasHit = (Physics.Raycast(getRay(t), out h, Mathf.Infinity, LayerHelper.GetLayerMask(hitOnlyLayers))); endTrace(h, t, hasHit); }
private bool IsOverlapping(out RaycastHit2D[] hits) { bool isOverlapping = false; int rootLayerMark = rootGO.layer; rootGO.layer = Physics2D.IgnoreRaycastLayer; int layerMask = LayerHelper.GetLayerMask(layerSize, true); List <RaycastHit2D> hitList = new List <RaycastHit2D>(); Bounds bounds = rootColl.bounds; Vector3 center = bounds.center; float halfWidth = bounds.extents.x; float halfHeight = bounds.extents.y; Vector3 right = rootTrans.right; int halfRayNum = 5; hits = Tool.RaycastAll2D(center - right * halfWidth, right, halfWidth * 2, halfHeight, halfRayNum, layerMask); hitList.AddRange(hits); hits = Tool.RaycastAll2D(center + right * halfWidth, -right, halfWidth * 2, halfHeight, halfRayNum, layerMask); hitList.AddRange(hits); hits = hitList.ToArray(); isOverlapping = Tool.IsCheck(hits); rootGO.layer = rootLayerMark; return(isOverlapping); }
void updateTouch(Touch t) { RaycastHit h = new RaycastHit(); bool hasHit = (Physics.Raycast(getRay(t), out h, Mathf.Infinity, LayerHelper.GetLayerMask(hitOnlyLayers))); if (!hasHit) { return; } updateTrace(h, t); }
private void ShootArrow() { //Calculate the damage of the arrow //If the current animation is DRAW, then the arrow is not at full power/speed //TODO: 50% threshold (arbitrary) for when the hand is not yet drawn if (_animator.GetCurrentAnimatorStateInfo(0).fullPathHash == AnimationHashHelper.STATE_DRAW) { aimTime = _animator.GetCurrentAnimatorStateInfo(0).normalizedTime; } else if (_animator.GetCurrentAnimatorStateInfo(0).fullPathHash == AnimationHashHelper.STATE_AIM) //Drawing is complete, currently 'AIM'ing { aimTime = 1f; } Transform direction = _shootingPoint; LayerMask lm = LayerHelper.GetLayerMask(_combatHandler.GetTeam()); RaycastHit hit; if (Physics.Raycast(CameraController.CC.CombatCamera.transform.position, CameraController.CC.CombatCamera.transform.forward, out hit, 100, lm)) { direction.LookAt(hit.point); } else { direction.LookAt(CameraController.CC.CombatCamera.transform.forward * 100); } // ProjectileController.PC.InstantiateProjectile (direction.position, direction.rotation, _combatHandler.GetComponent<PhotonView>().viewID, (int)(aimTime * _damage), ProjectileController.TYPE.ARROW_ROPE); // // go = PhotonNetwork.Instantiate ("Rope_05", _combatHandler.transform.position, Quaternion.identity, 0); GameObject projectileInstance = PhotonNetwork.Instantiate("RopeArrow", direction.position, direction.rotation, 0); // projectileInstance.transform.position = direction.position; // projectileInstance.transform.rotation = direction.rotation; // PhotonView pv = PhotonView.Find (photonViewID); CombatHandler ch = _combatHandler; Weapon weapon = projectileInstance.GetComponent <Weapon> (); weapon.SetOwner(ch); Arrow arrow = weapon.GetDamagingPoints()[0].GetComponent <Arrow>(); // arrow.gameObject.layer = LayerHelper.GetAttackBoxLayer(ch.GetTeam()); arrow.SetDamagableLayers(); arrow.GetComponent <Collider> ().enabled = true; arrow.SetIsMine(true); weapon.SetDamage(25); }
LayerMask getMask(CameraCast c) { LayerMask mask = (LayerMask)LayerHelper.GetLayerMask(c.hitOnlyLayers); if (c.CullingMask == CullingMaskUsage.Add) { mask |= c.castOn.cullingMask; } else if (c.CullingMask == CullingMaskUsage.Limit) { mask &= c.castOn.cullingMask; } return(mask); }
public void UpdateTouch(Touch t) { if (!enabled) { return; } Ray touchRay = getRay(t); // Raycast against the hit layers to get new position based on touch position RaycastHit h = new RaycastHit(); bool hasHit = (Physics.Raycast(touchRay, out h, Mathf.Infinity, LayerHelper.GetLayerMask(hitOnlyLayers))); if (!hasHit) { return; } Vector3 cPos = h.point.UpTowards(targetCamera.transform.position, upDir, liftBy); // Check if we are within bounds (if defined) if (DragBounds != null) { // Raycast from the target position to the centre of the bounds, if we hit it, we are outside it. Vector3 diffDir = (DragBounds.transform.position - cPos).normalized; RaycastHit colH; hasHit = DragBounds.Raycast(new Ray(cPos, diffDir), out colH, Vector3.Distance(cPos, DragBounds.transform.position)); // If we hit the bounds, set the position to where we hit on the bounds if (hasHit) { cPos = colH.point; } } // Move the dragger to the new position updateDragger(cPos, t, hasHit); }
private void ShootArrow() { //Calculate the damage of the arrow //If the current animation is DRAW, then the arrow is not at full power/speed //TODO: 50% threshold (arbitrary) for when the hand is not yet drawn if (_animator.GetCurrentAnimatorStateInfo(0).fullPathHash == AnimationHashHelper.STATE_DRAW) { aimTime = _animator.GetCurrentAnimatorStateInfo(0).normalizedTime; } else if (_animator.GetCurrentAnimatorStateInfo(0).fullPathHash == AnimationHashHelper.STATE_AIM) //Drawing is complete, currently 'AIM'ing { aimTime = 1f; } // Transform direction = _shootingPoint; // direction.LookAt (Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.5f))); // direction.position = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.5f)); // direction.LookAt(Camera.main.ViewportToWorldPoint (new Vector3 (0.5f, 0.5f, 0.5f))); // direction.LookAt(Camera.main.ViewportPointToRay (new Vector3 (0.5f, 0.5f, 0.5f)).GetPoint(20)); // direction.position = Camera.main.ViewportPointToRay (new Vector3 (0.5f, 0.5f, 0.5f)).GetPoint(2); // direction.LookAt (CameraController.CC.CombatCamera.transform.forward * 10000000); // Ray target = Camera.main.ViewportPointToRay (new Vector3 (0.5f, 0.5f, 0.5f)); LayerMask lm = LayerHelper.GetLayerMask(_combatHandler.GetTeam()); RaycastHit hit; if (Physics.Raycast(CameraController.CC.CombatCamera.transform.position, CameraController.CC.CombatCamera.transform.forward, out hit, 100, lm)) { _shootingPoint.LookAt(hit.point); } else { _shootingPoint.LookAt(CameraController.CC.CombatCamera.transform.forward * 100); } ProjectileController.PC.InstantiateProjectile(_shootingPoint.position, _shootingPoint.rotation, _combatHandler.GetComponent <PhotonView> ().viewID, (int)(aimTime * _damage), ProjectileController.TYPE.ARROW_NORMAL); // Debug.Break (); }
public override void Update() { base.Update(); Bounds bounds = coll.bounds; Vector3 extents = bounds.extents; Vector3 right = rootTrans.right; RaycastHit2D[] hit2Ds = Tool.RaycastAll2D(bounds.center, right, extents.x, extents.y, 5, LayerHelper.GetLayerMask(layerSize, true)); if (!Tool.IsCheck(hit2Ds)) { Vector3 newPosition = rootTrans.position; newPosition += rootTrans.right * sprintingSpeed * Time.deltaTime; if (!Tool.IsOutOfCameraX(newPosition.x, -coll.bounds.extents.x)) { rootTrans.position = newPosition; } } }
// Update is called once per frame void Update() { Bounds bounds = coll2D.bounds; Vector3 extents = bounds.extents; RaycastHit2D[] hit2Ds = Tool.RaycastAll2D(bounds.center, -myTrans.up, extents.y, extents.x, 2, LayerHelper.GetLayerMask(standLayerNames, true)); bool checkStand = Tool.IsCheck(hit2Ds); if (!checkStand) { if (uncheckStandStartTime < 0) { uncheckStandStartTime = Time.time; } float deltaTime = Time.time - uncheckStandStartTime; myTrans.position += (Vector3)(gravity * deltaTime * deltaTime * .5f); } else { Vector2 point = AveragePoint(hit2Ds); Vector3 position = myTrans.position; float x = position.x; float y = point.y + extents.y - (bounds.center.y - position.y); float z = position.z; Vector3 newPosition = Vector3.right * x + Vector3.up * y + Vector3.forward * z; myTrans.position = newPosition; uncheckStandStartTime = -1; } }