Ejemplo n.º 1
0
 public bool collidingWithBuilding(bool checkSameGroup = true)
 {
     foreach (GameObject g in objectsTriggered)
     {
         //TODO : debug this. I need to make sure "triggers" are fine
         //Debug.Log("objectsTriggered= "+g.name);
         if (ConstraintController.layerIsInMask(g.layer, ConstraintController.getBuildingsMask()))
         {
             if (!checkSameGroup || g.GetComponent <BeyondComponent>().beyondGroup != beyondGroup)
             {
                 //Debug.Log("collidingWithBuilding TRUE. Object is in group " + g.GetComponent<BeyondComponent>().beyondGroup.name + " from group " + (beyondGroup!=null ? beyondGroup.name : "NULL"));
                 return(true);
             }
         }
     }
     //Debug.Log("collidingWithBuilding FALSE");
     return(false);
 }
Ejemplo n.º 2
0
        private void MovePlaceableObjectToMouse()
        {
            Ray        ray1 = Camera.main.ScreenPointToRay(mousePosition);
            RaycastHit hitInfo;

            // filter the raycast based on whether this template should be shown on terrain or not
            //LayerMask layerMask = (ConstraintController.ShowOnTerrain(currentBC.template) ? ConstraintController.getTerrainMask() : ConstraintController.getBuildingsMask()) ;
            Vector3 position;

            // 1 - If we hit a building, show the Ghost on it
            if (Physics.Raycast(ray1, out hitInfo, UIController.Instance.forwardOffset, ConstraintController.getBuildingsMask()))
            {
                //Debug.Log("Move to mouse: hit a BUILDING");
                position = ConstraintController.PlaceGhost(currentBC, hitInfo.point, ConstraintController.getBuildingsMask());
            }

            // 2 - If we hit terrain, show the Ghost on it
            else if (Physics.Raycast(ray1, out hitInfo, UIController.Instance.forwardOffset, ConstraintController.getTerrainMask()))
            {
                //Debug.Log("Move to mouse: hit TERRAIN");
                position = ConstraintController.PlaceGhost(currentBC, hitInfo.point, ConstraintController.getTerrainMask());
            }

            // 3 - If we hit nothing, just make the object float in front of us at a distance of forwardOffset
            else
            {
                //Debug.Log("Move to mouse: FLOAT");
                Ray ray2 = Camera.main.ScreenPointToRay(mousePosition);
                position = Camera.main.transform.position + ray2.direction * UIController.Instance.forwardOffset;
            }

            // If I'm in a group, I'm snapped, so only move if I'm a bit far from my current position
            if (currentBC.beyondGroup == null || Vector3.Distance(position, currentBC.transform.position) > groupSnapTolerance)
            {
                currentBC.MoveGhost(position);
            }
            Snap();
        }
Ejemplo n.º 3
0
        // Update is called once per frame
        void Update()
        {
            //if (UIController.Instance.gameMode == gameMode.free)
            //{
            timer += Time.deltaTime;
            if (timer > 0.2f)
            {
                // TO DO : Should I check for different masks to prevent jumping from non-jumpable objects ?
                // Does such a thing even exists ?
                isOnGround = Physics.CheckSphere(groundCheck.position, groundDistance, ConstraintController.getTerrainMask()) || Physics.CheckSphere(groundCheck.position, groundDistance, ConstraintController.getBuildingsMask());
                timer      = 0f;
                if (isOnGround && velocity.y < 0)
                {
                    velocity.y = -2f;
                }
            }

            float x = Input.GetAxis("Horizontal");
            float z = Input.GetAxis("Vertical");

            running = Input.GetKey(KeyCode.LeftShift);

            Vector3 move = transform.right * x + transform.forward * z;

            cc.Move(move * speed * (running ? 2.5f : 1) * Time.deltaTime);

            if (Input.GetButtonDown("Jump") && isOnGround)
            {
                velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
            }

            velocity.y += gravity * Time.deltaTime * 5f;
            cc.Move(velocity * Time.deltaTime);
            //}
        }
Ejemplo n.º 4
0
        private List <BeyondGroup> findCloseGroups(BeyondComponent bc, out BeyondGroup closestGroup)
        {
            List <BeyondGroup> result = new List <BeyondGroup>();

            // Find the groups that are close to this BeyondComponent
            Collider[] collidersInGroup = Physics.OverlapBox(bc.transform.position, bc.template.castBox + new Vector3(1f, 1f, 1f) * groupSnapTolerance, bc.transform.rotation, ConstraintController.getBuildingsMask());
            closestGroup = null;
            float minDistance = 0;

            foreach (Collider c in collidersInGroup)
            {
                BeyondComponent collided_bc = c.transform.GetComponent <BeyondComponent>();
                if (collided_bc != null && collided_bc.beyondGroup != null)
                {
                    result.Add(collided_bc.beyondGroup);
                    float distance = Vector3.Distance(bc.transform.position, collided_bc.transform.position);
                    if (closestGroup == null || distance < minDistance)
                    {
                        minDistance  = distance;
                        closestGroup = collided_bc.beyondGroup;
                    }
                }
            }
            UIController.Instance.SetClosestGroup(closestGroup);

            return(result);
        }