public List<Vector3> move(Level level, Transform transform, TimeDirection timeD, out Vector3 rotation)
    {
        List <Vector3> movement = new List<Vector3>(); //might not want to return empty objects this often
        //move these to start
        rotation = Vector3.zero;
        //first check if grabbing something
        //might want to add delay before going further to allow for turning before moving block
        if(level.getEntity(transform.position,transform.TransformDirection(Vector3.forward)).type==states.block)
        {
            grabbing = true;
        }
        //otherwise turn to block
        else
        {
            List<Entity> temp = level.getsurroundingEntity(transform.position);
            {
                foreach(Entity entity in temp)
                {
                    if(entity.type==states.block)
                    {
                        grabbing = true;
                        float angle = Vector3.Angle(transform.TransformDirection(Vector3.forward),entity.obj.transform.position-transform.position);
                        Vector3 cross = Vector3.Cross(transform.TransformDirection(Vector3.forward),entity.obj.transform.position-transform.position);
                        rotation = (cross.y>0)?new Vector3(0,angle,0):new Vector3(0,-angle,0);
                        return movement;
                    }
                }
            }
        }
        //if block is in front
           		if(grabbing)
        {
            if(transform.TransformDirection(Vector3.forward)==Vector3.right||transform.TransformDirection(Vector3.forward)==Vector3.left)
            {
                if (timeD.direction==Vector3.right)
                    movement.Add (Vector3.right);
                else if(timeD.direction==Vector3.left)
                    movement.Add (Vector3.left);
            }
            else if(transform.TransformDirection(Vector3.forward)==Vector3.forward||transform.TransformDirection(Vector3.forward)==Vector3.back)
            {
                if (timeD.direction==Vector3.forward)
                    movement.Add (Vector3.forward);
                else if(timeD.direction==Vector3.back)
                    movement.Add (Vector3.back);
            }
            else{
                return new List<Vector3>();
            }

            //if returning actual values, then fix up the moves to account for both objects
            if (movement.Count>0&&timeD.time>0.1f)
                return move_checks(level, movement,transform);
            }
        return new List<Vector3>();
    }
Exemplo n.º 2
0
    public Vector3 displace(Level level, Vector3 position, Transform transform)
    {
        Vector3 forward = transform.TransformDirection(Vector3.forward);
            if(level.getEntity(position,forward).type==states.empty) //if there is no collision ahead, and the time is large enough then move
            {
                if(level.getEntity(position,forward+Vector3.down).type==states.empty)
                {
                    return forward+Vector3.down;
                }
                else
                {
                    return forward; //translate object in forward direction
                }
            }
            else if(level.getEntity(position,forward).type!=states.empty
            && level.getEntity(position,Vector3.up).type== states.empty
            && level.getEntity(position+forward,Vector3.up).type==states.empty) //if no unit above the block infront, and no block above, then move up a block
            {
                    return Up+forward;
            }

            return Vector3.zero;
    }
Exemplo n.º 3
0
    public Vector3 move(Level level, Transform transform, TimeDirection timeD,float timetoMove, out Vector3 rotation)
    {
        //currently when going to hang off a ledge you are falling for a split second
        //could be an issue??

        rotation = Vector3.zero;
        if(level.getEntity(transform.position,Vector3.down).type==states.empty)
        {
            return Down;
        }

        if(timeD.direction!=transform.TransformDirection(Vector3.forward)) //if direction that is designated for character does not equal current rotation
        {
            if (timeD.direction==Vector3.right) //if right
            {
                rotation = new Vector3(0,90,0)-transform.eulerAngles; //turn towards right
            }
            else if(timeD.direction==Vector3.left)
            {
                rotation = new Vector3(0,-90,0)-transform.eulerAngles;
            }
            else if(timeD.direction==Vector3.forward)
            {
                rotation = new Vector3(0,0,0)-transform.eulerAngles;
            }
            else if(timeD.direction==Vector3.back)
            {
                rotation = new Vector3(0,180,0)-transform.eulerAngles;
            }
        }

        if(timeD.time>timetoMove)
            {
                return displace(level,transform.position, transform);
            }

        return Vector3.zero;
    }
    // Update is called once per frame
    public Vector3 move(Level level, Transform transform, TimeDirection timeD, out Vector3 rotation)
    {
        //set up return value
        rotation = Vector3.zero;

        if (timeD.time>0.1f)
        {
            //if right
            //check if block directly to right, if so then rotate
            if (timeD.direction==Vector3.right)
            {
                if(level.getEntity(transform.position,transform.TransformDirection(Vector3.right)).type==states.block)
                {
                    rotation = transform.TransformDirection(new Vector3(0,90,0));
                    return Vector3.zero;
                }
                //if no block to the right, then check if block forward and right from the characters is empty.
                //if so then move around the corner
                //otherwise if there is a block forward and right, move right
                //in both cases, make sure there is no block above the new position

                else
                {
                    if(level.getEntity(transform.position+transform.TransformDirection(Vector3.forward),transform.TransformDirection(Vector3.right)).type==states.block
                        && level.getEntity(transform.position,Vector3.up+transform.TransformDirection(Vector3.right)).type==states.empty)
                    {
                        return transform.TransformDirection(Vector3.right);
                    }
                    else if(level.getEntity(transform.position,transform.TransformDirection(Vector3.forward)+transform.TransformDirection(Vector3.right)).type==states.empty
                        && level.getEntity(transform.position,Vector3.up+transform.TransformDirection(Vector3.right)+transform.TransformDirection(Vector3.forward)).type==states.empty)
                    {
                        rotation = transform.TransformDirection(new Vector3(0,-90,0));
                        return transform.TransformDirection(Vector3.forward+Vector3.right);
                    }
                }
            }
            //inverse of previous section
            else if(timeD.direction==Vector3.left)
            {
                if(level.getEntity(transform.position,transform.TransformDirection(Vector3.left)).type==states.block)
                    {
                        rotation = new Vector3(0,-90,0);
                        return Vector3.zero;
                    }
                else
                {
                    if(level.getEntity(transform.position,transform.TransformDirection(Vector3.forward)+transform.TransformDirection(Vector3.left)).type==states.block
                        && level.getEntity(transform.position,Vector3.up+transform.TransformDirection(Vector3.left)).type==states.empty)
                    {
                        return transform.TransformDirection(Vector3.left);
                    }
                    else if(level.getEntity(transform.position,transform.TransformDirection(Vector3.forward)+transform.TransformDirection(Vector3.left)).type==states.empty
                        && level.getEntity(transform.position,Vector3.up+transform.TransformDirection(Vector3.left)+transform.TransformDirection(Vector3.forward)).type==states.empty)
                    {
                        rotation = transform.TransformDirection(new Vector3(0,90,0));
                        return transform.TransformDirection(Vector3.forward+Vector3.left);
                    }
                }
            }

            //if up or down is pressed
            //if it's up, check if character can climb up
            //if down then fall
            else if (timeD.direction==Vector3.forward)
            {
                if (level.getEntity(transform.position,Vector3.up).type==states.empty&&
                    level.getEntity(transform.position+Vector3.up,transform.TransformDirection(Vector3.forward)).type==states.empty)
                {
                        return Vector3.up+transform.TransformDirection(Vector3.forward);
                }
            }

            else if (timeD.direction==Vector3.back)
            {
                return Vector3.down;
            }

            Debug.Log("SHOULN'T BE REACHIGN THIS");
            return Vector3.zero;
        }

        else
            return Vector3.zero;
    }
 private List<Vector3> move_checks(Level level, List<Vector3> movement, Transform transform)
 {
     movement.Add (movement[0]);
     //if the position behind the character is the place being moved to, then follow this logic
     if(transform.TransformDirection(Vector3.back)==movement[0])
     {
         //if block behind you, then return empty
         if(level.getEntity(transform.position,transform.TransformDirection(Vector3.back)).type==states.block)
         {
             return new List<Vector3>();
         }
         //other nothing to step on behind you, then fall down and pull block
         if(level.getEntity(transform.position,transform.TransformDirection(Vector3.back)+Vector3.down).type==states.empty)
         {
             movement[1]=(Vector3.down+transform.TransformDirection(Vector3.back));
         }
     }
     //otherwise just push blocks
     else{
         if(level.getEntity(transform.position+transform.TransformDirection(Vector3.forward),Vector3.down).type==states.empty)
         {
             movement[1]=(Vector3.zero);
         }
     }
     return movement;
 }