void Update() { this.pitchInput = Input.GetAxis("Mouse Y"); float angularVelocity = this.transform.parent.GetComponent <PlayerController> ().angularVelocity; transform.rotation *= Quaternion.AngleAxis(pitchInput * Time.deltaTime * angularVelocity, Vector3.right); //target display Vector3i target = GetTarget(false); if (target != null) { this.debugObject.transform.position = target.Floatify(); //TODO: OPTIMIZE!!!! Vector3i target2 = GetTarget(true); Vector3 finalTarget = target2.Subtract(target).Floatify(); //this.debugObject.transform.rotation = Quaternion.LookRotation(finalTarget); //this.debugObject.transform.rotation = Quaternion.Euler(target.floatify()); //Vector3 finalTarget2 = new Vector3(finalTarget.z, finalTarget.y, -finalTarget.x); //Vector3 finalTarget2 = new Vector3(0.2f, 0, 0); this.debugObject.transform.rotation = Quaternion.LookRotation(finalTarget); this.debugObject.SetActive(true); } else { this.debugObject.SetActive(false); } }
public List <Vector3i> GetColliderVoxels(Vector3 playerPosition, int colliderDistance) { List <Vector3i> result = new List <Vector3i>(); Vector3i intPlayerPosition = new Vector3i((int)playerPosition.x, (int)playerPosition.y, (int)playerPosition.z); intPlayerPosition = intPlayerPosition.Subtract(this.worldPosition); Vector3i maxDistance = new Vector3i(); Vector3i minDistance = new Vector3i(); maxDistance.x = intPlayerPosition.x + colliderDistance; minDistance.x = intPlayerPosition.x - colliderDistance; if (maxDistance.x >= 0 && minDistance.x <= this.size) { maxDistance.z = intPlayerPosition.z + colliderDistance; minDistance.z = intPlayerPosition.z - colliderDistance; if (maxDistance.z >= 0 && minDistance.z <= this.size) { maxDistance.y = intPlayerPosition.y + colliderDistance; minDistance.y = intPlayerPosition.y - colliderDistance; if (maxDistance.y >= 0 && minDistance.y <= this.size) { int startX = Mathf.Max(minDistance.x, 0); int endX = Mathf.Min((maxDistance.x + 1), this.size); int startY = Mathf.Max(minDistance.y, 0); int endY = Mathf.Min((maxDistance.y + 1), this.size); int startZ = Mathf.Max(minDistance.z, 0); int endZ = Mathf.Min((maxDistance.z + 1), this.size); for (int x = 0; x < (endX - startX); x++) { for (int z = 0; z < (endZ - startZ); z++) { for (int y = 0; y < (endY - startY); y++) { Vector3i finalPosition = new Vector3i(x + startX, y + startY, z + startZ); byte blockType = this.blocks [finalPosition.x, finalPosition.y, finalPosition.z].type; if (this.blockDatabase.blockMaterials[blockType].collider && !this.blocks[finalPosition.x, finalPosition.y, finalPosition.z].isInside) { result.Add(finalPosition); } } } } } } } return(result); }
private Vector3i GetLocalPosition(Vector3i worldPosition) { return(worldPosition.Subtract(this.worldPosition)); }