Exemplo n.º 1
0
    // Use this for initialization

    void Start()
    {
        playerScript  = player.GetComponent <PlayerScript>();
        physicsScript = player.GetComponent <PhysicsScript>();
        text          = textGameObject.GetComponent <Text>();
        camera        = GetComponent <Camera>();
    }
Exemplo n.º 2
0
 //Change player properties on trigger enter
 private void OnTriggerEnter2D(Collider2D collision)
 {
     //behaviour for when player is scared
     if (collision.tag == "Shadow" && this.gameObject.layer != 14)
     {
         SetAnimatorBool("Scared", true);
         SetAllInputFalse();
         currentSpeed = PhysicsScript.EffectedFloat(NormalSpeed, 0.25f);
     }
     else if (collision.tag == "GravityWell" && this.gameObject.layer != 14)
     {
         SetAllInputFalse();
         PhysicsScript.GravityIncrease(this.gameObject, 0.5f, 1.5f);
         currentSpeed = PhysicsScript.EffectedFloat(NormalSpeed, 1.5f);
     }
     //makes player visible when entering mirror in mirrorworld
     else if (collision.tag == "Mirror" && this.gameObject.layer == 14)
     {
         spriteRenderer.enabled = true;
     }
     else if (collision.tag == "Inversion")
     {
         currentSpeed = PhysicsScript.EffectedFloat(currentSpeed, -1.1f);
     }
 }
 void Awake()
 {
     gameControllerScript = GameObject.FindObjectOfType <GameControllerScript>();
     physs = new PhysicsScript();
     gameControllerScript.enemies.Add(this.gameObject);
     player = gameControllerScript.FindOneRandomPlayer();
 }
Exemplo n.º 4
0
 void Awake()
 {
     gameControllerGameObject = GameObject.FindGameObjectWithTag(gameControllerTag);
     anima  = GetComponent <Animator> ();
     physs  = this.gameObject.GetComponent <PhysicsScript> ();
     player = FindOneRandomPlayer();
 }
Exemplo n.º 5
0
 // Use this for initialization
 void Start()
 {
     physicsScript            = GetComponent <PhysicsScript>();
     sprite                   = GetComponent <SpriteRenderer>();
     pusherScript             = GetComponent <PusherScript>();
     movementControllerScript = GetComponent <MovementControllerScript>();
     facing                   = 1;
 }
Exemplo n.º 6
0
    // Use this for initialization

    void Start()
    {
        physicsScript            = GetComponent <PhysicsScript>();
        sprite                   = GetComponent <SpriteRenderer>();
        graberScript             = GetComponent <GraberScript>();
        movementControllerScript = GetComponent <MovementControllerScript>();
        inputScript              = GetComponent <KeyboardInputScript>();
        facing                   = 1;
    }
Exemplo n.º 7
0
 private void Awake()
 {
     if (_instance == null)
     {
         _instance = this;
     }
     else
     {
         Destroy(this);
     }
 }
Exemplo n.º 8
0
    //Change player properties on trigger enter
    private void OnTriggerEnter2D(Collider2D collision)
    {
        //behaviour for when player is scared
        if (collision.tag == "GravityWell" && this.gameObject.layer != 14)
        {
            PhysicsScript.GravityIncrease(this.gameObject, 0.5f, 1.5f);
            normalSpeed = moveSpeed;
            moveSpeed   = PhysicsScript.EffectedFloat(moveSpeed, 2);
        }
        //makes player visible when entering mirror in mirrorworld

        else if (collision.tag == "Inversion")
        {
            normalSpeed = moveSpeed;
            moveSpeed   = PhysicsScript.EffectedFloat(moveSpeed, 0.1f);
        }
    }
Exemplo n.º 9
0
 //Restore player properties on trigger exit
 private void OnTriggerExit2D(Collider2D collision)
 {
     if (collision.transform.tag == "Shadow")
     {
         SetAnimatorBool("Scared", false);
         SetAllInputFalse();
         currentSpeed = PhysicsScript.EffectedFloat(NormalSpeed);
     }
     else if (collision.tag == "GravityWell")
     {
         PhysicsScript.ResetGravity(this.gameObject, scale);
         currentSpeed = PhysicsScript.EffectedFloat(NormalSpeed);
     }
     else if (collision.tag == "Inversion")
     {
         currentSpeed = PhysicsScript.EffectedFloat(NormalSpeed);
     }
     //makes player invisible when leaving in mirrorworld
     else if (collision.tag == "Mirror" && this.gameObject.layer == 14)
     {
         spriteRenderer.enabled = false;
     }
 }
Exemplo n.º 10
0
 // Use this for initialization
 void Start()
 {
     physicsScript            = GetComponent <PhysicsScript>();
     movementControllerScript = GetComponent <MovementControllerScript>();
 }
Exemplo n.º 11
0
    public void DoFixedUpdate()
    {
        // If both controllers aren't ready, ignore the player input
        if (!UFE.GetPlayer1Controller().isReady || !UFE.GetPlayer2Controller().isReady) return;

        // Training Mode
        if ((playerNum == 1 && UFE.gameMode == GameMode.TrainingRoom && UFE.config.trainingModeOptions.p1Life == LifeBarTrainingMode.Refill) ||
            (playerNum == 2 && UFE.gameMode == GameMode.TrainingRoom && UFE.config.trainingModeOptions.p2Life == LifeBarTrainingMode.Refill)) {
            if (!UFE.FindDelaySynchronizedAction(this.RefillLife))
                UFE.DelaySynchronizedAction(this.RefillLife, UFE.config.trainingModeOptions.refillTime);
        }

        if ((playerNum == 1 && UFE.gameMode == GameMode.TrainingRoom && UFE.config.trainingModeOptions.p1Gauge == LifeBarTrainingMode.Refill) ||
            (playerNum == 2 && UFE.gameMode == GameMode.TrainingRoom && UFE.config.trainingModeOptions.p2Gauge == LifeBarTrainingMode.Refill)) {
            if (!UFE.FindDelaySynchronizedAction(this.RefillGauge))
                UFE.DelaySynchronizedAction(this.RefillGauge, UFE.config.trainingModeOptions.refillTime);
        }

        if (UFE.gameMode == GameMode.TrainingRoom && myInfo.currentGaugePoints < myInfo.maxGaugePoints &&
            ((playerNum == 1 && UFE.config.trainingModeOptions.p1Gauge == LifeBarTrainingMode.Infinite) ||
            (playerNum == 2 && UFE.config.trainingModeOptions.p2Gauge == LifeBarTrainingMode.Infinite))) RefillGauge();

        if (UFE.gameMode == GameMode.TrainingRoom && myInfo.currentLifePoints < myInfo.lifePoints &&
            ((playerNum == 1 && UFE.config.trainingModeOptions.p1Life == LifeBarTrainingMode.Infinite) ||
            (playerNum == 2 && UFE.config.trainingModeOptions.p2Life == LifeBarTrainingMode.Infinite))) RefillLife();

        // Debugger
        if (debugger != null && UFE.config.debugOptions.debugMode){
            debugger.text = "";
            if (UFE.config.debugOptions.debugMode) {
                debugger.text += "-----Character Info-----\n";
                if (debugInfo.lifePoints) debugger.text += "Life Points: " + myInfo.currentLifePoints + "\n";
                if (debugInfo.position) debugger.text += "Position: " + transform.position + "\n";
                if (debugInfo.currentState) debugger.text += "State: " + currentState + "\n";
                if (debugInfo.currentSubState) debugger.text += "Sub State: " + currentSubState + "\n";
                if (debugInfo.stunTime && stunTime > 0) debugger.text += "Stun Time: " + stunTime + "\n";
                if (opControlsScript != null && opControlsScript.comboHits > 0) {
                    debugger.text += "Current Combo\n";
                    if (debugInfo.comboHits) debugger.text += "- Total Hits: "+ opControlsScript.comboHits + "\n";
                    if (debugInfo.comboDamage) {
                        debugger.text += "- Total Damage: " + opControlsScript.comboDamage + "\n";
                        debugger.text += "- Hit Damage: " + opControlsScript.comboHitDamage + "\n";
                    }
                }

                // Other uses
                //if (potentialParry > 0) debugger.text += "Parry Window: "+ potentialParry + "\n";
                //debugger.text += "Air Jumps: "+ myPhysicsScript.currentAirJumps + "\n";

                if (UFE.config.debugOptions.p1DebugInfo.currentMove && currentMove != null) {
                    debugger.text += "Move: "+ currentMove.name + " ("+ currentMove.currentFrame +"/"+ currentMove.totalFrames +") \n";
                    /*if (currentMove.chargeMove) {
                        debugger.text += "First Input Charge: "+ myMoveSetScript.chargeValues[currentMove.buttonSequence[0]] + "\n";
                    }*/
                    //debugger.text += "StartupFrames: "+ currentMove.moveClassification.startupSpeed +" \n";
                }
            }
            if (aiDebugger != null && debugInfo.aiWeightList) debugger.text += aiDebugger;
        }

        // Once per game
        if (opHitBoxesScript == null) {
            opControlsScript = opponent.GetComponent<ControlsScript>();
            opPhysicsScript = opponent.GetComponent<PhysicsScript>();
            opHitBoxesScript = opponent.GetComponentInChildren<HitBoxesScript>();
            opInfo = opControlsScript.myInfo;

            if (myInfo.enableAlternativeColor){
                if (gameObject.name == "Player2" && character.name == opControlsScript.character.name){  // Alternative Costume
                    Renderer[] charRenders = character.GetComponentsInChildren<Renderer>();
                    foreach(Renderer charRender in charRenders){
                        charRender.material.color = myInfo.alternativeColor;
                        //charRender.material.shader = Shader.Find("VertexLit");
                        //charRender.material.SetColor("_Emission", myInfo.alternativeColor);
                    }
                }
            }

            Renderer[] charRenderers = character.GetComponentsInChildren<Renderer>();
            List<Shader> shaderList = new List<Shader>();
            List<Color> colorList = new List<Color>();
            foreach(Renderer char_rend in charRenderers){
                //if (char_rend.material.HasProperty("color") && char_rend.material.HasProperty("shader")){
                    shaderList.Add(char_rend.material.shader);
                    colorList.Add(char_rend.material.color);
                //}
            }
            normalShaders = shaderList.ToArray();
            normalColors = colorList.ToArray();

            myMoveSetScript.PlayBasicMove(myMoveSetScript.basicMoves.idle);
        }

        // Once per round
        if ((gameObject.name == "Player1" && !introPlayed && currentMove == null) ||
            (gameObject.name == "Player2" && !introPlayed && opControlsScript.introPlayed && currentMove == null))
        {
            KillCurrentMove();
            CastMove(myMoveSetScript.intro, true, true, false);
            if (currentMove == null) {
                introPlayed = true;
                UFE.CastNewRound();
            }
        }

        // Resolve move
        resolveMove();

        // Check inputs
        translateInputs(inputController);

        // Validate rotation
        validateRotation();

        // Input Viewer
        List<InputReferences> inputList = new List<InputReferences>();
        foreach (InputReferences inputRef in inputController.inputReferences){
            if (debugger != null && UFE.config.debugOptions.debugMode && debugInfo.inputs){
                debugger.text += inputRef.inputButtonName + " - "+ inputRef.heldDown + "\n";
            }
            if (inputRef.heldDown > 0 && inputRef.heldDown <= (2f/(float)UFE.config.fps)){
                inputList.Add(inputRef);
            }
        }
        UFE.CastInput(inputList.ToArray(), playerNum);

        // Force character local position
        if (ignoreAnimationTransform && (currentMove == null || !currentMove.applyRootMotion))
            character.transform.localPosition = new Vector3(0, 0, 0);

        // Force stand state
        if (!myPhysicsScript.freeze
            && !isDead
            && currentSubState != SubStates.Stunned
            && introPlayed
            && myPhysicsScript.IsGrounded()
            && !myPhysicsScript.IsMoving()
            && currentMove == null
            && !myMoveSetScript.IsBasicMovePlaying(myMoveSetScript.basicMoves.idle)
            && !myMoveSetScript.IsAnimationPlaying("fallStraight")
            && isAxisRested(inputController)
            && !myPhysicsScript.isTakingOff
            && !myPhysicsScript.isLanding
            && !blockStunned
            && currentState != PossibleStates.Crouch
            && !isBlocking
            ){

                myMoveSetScript.PlayBasicMove(myMoveSetScript.basicMoves.idle);
                currentState = PossibleStates.Stand;
                currentSubState = SubStates.Resting;
                if (UFE.config.blockOptions.blockType == BlockType.AutoBlock
                    && myMoveSetScript.basicMoves.blockEnabled) potentialBlock = true;
        }

        if (myMoveSetScript.IsAnimationPlaying("idle")
            && !UFE.config.lockInputs
            && !UFE.config.lockMovements) {
            afkTimer += Time.fixedDeltaTime;
            if (afkTimer >= myMoveSetScript.basicMoves.idle.restingClipInterval) {
                afkTimer = 0;
                int clipNum = Mathf.RoundToInt(Random.Range(2, 6));
                if (myMoveSetScript.AnimationExists("idle_" + clipNum)) {
                    myMoveSetScript.PlayBasicMove(myMoveSetScript.basicMoves.idle, "idle_" + clipNum, false);
                }
            }
        } else {
            afkTimer = 0;
        }

        // Character colliders based on collision mass and body colliders
        normalizedDistance = Mathf.Clamp01(Vector3.Distance(opponent.transform.position, transform.position) / UFE.config.cameraOptions.maxDistance);
        if (!ignoreCollisionMass && !opControlsScript.ignoreCollisionMass) {
            float pushForce = myHitBoxesScript.TestCollision(opHitBoxesScript.hitBoxes);
            if (pushForce > 0) {
                if (transform.position.x < opponent.transform.position.x) {
                    transform.Translate(new Vector3(-.1f * pushForce, 0, 0));
                }else{
                    transform.Translate(new Vector3(.1f * pushForce, 0, 0));
                }
                if (opponent.transform.position.x == UFE.config.selectedStage.rightBoundary){
                    opponent.transform.Translate(new Vector3(-.2f * pushForce, 0, 0));
                }
            }

            pushForce = myInfo.physics.groundCollisionMass - Vector3.Distance(transform.position, opponent.transform.position);
            if (pushForce > 0) {
                if (transform.position.x < opponent.transform.position.x) {
                    transform.Translate(new Vector3(-.5f * pushForce, 0, 0));
                }else{
                    transform.Translate(new Vector3(.5f * pushForce, 0, 0));
                }
                if (opponent.transform.position.x == UFE.config.selectedStage.rightBoundary){
                    opponent.transform.Translate(new Vector3(-.2f * pushForce, 0, 0));
                }
            }
        }

        // Shake character
        if (shakeDensity > 0) {
            shakeDensity -= Time.fixedDeltaTime;
            if (myHitBoxesScript.isHit && myPhysicsScript.freeze){
                if (shakeCharacter) shake();
                if (shakeCamera) shakeCam();
            }else{
                if (UFE.config.bounceOptions.shakeCamOnBounce && myPhysicsScript.isBouncing) shakeCam();
            }
        }else if (shakeDensity < 0) {
            shakeDensity = 0;
            shakeCamera = false;
            shakeCharacter = false;
        }

        // Validate Parry
        if (potentialParry > 0){
            potentialParry -= Time.fixedDeltaTime;
            if (potentialParry <= 0) potentialParry = 0;
        }

        // Update head movement
        if (headLookScript != null && opHitBoxesScript != null)
            headLookScript.target = opHitBoxesScript.GetPosition(myInfo.headLook.target);

        // Execute Move
        if (currentMove != null) ReadMove(currentMove);

        // Apply Stun
        if ((currentSubState == SubStates.Stunned || blockStunned) && stunTime > 0 && !myPhysicsScript.freeze && !isDead)
            ApplyStun();

        // Apply Forces
        myPhysicsScript.ApplyForces(currentMove);
    }
Exemplo n.º 12
0
    void Start()
    {
        if (gameObject.name == "Player1") {
            transform.position = new Vector3(UFE.config.roundOptions.p1XPosition, .009f, 0);
            opponent = GameObject.Find("Player2");
            if (UFE.config.player1Character == null)
                Debug.LogError("Player 1 character not found! Make sure you have set the characters correctly in the Global Editor");

            myInfo = (CharacterInfo) Instantiate(UFE.config.player1Character);
            UFE.config.player1Character = myInfo;

            debugger = UFE.debugger1;
            mirror = -1;
            playerNum = 1;

            inputController = UFE.GetPlayer1Controller();
            debugInfo = UFE.config.debugOptions.p1DebugInfo;
        }else{
            transform.position = new Vector3(UFE.config.roundOptions.p2XPosition, .009f, 0);
            opponent = GameObject.Find("Player1");
            if (UFE.config.player2Character == null)
                Debug.LogError("Player 2 character not found! Make sure you have set the characters correctly in the Global Editor");

            myInfo = (CharacterInfo) Instantiate(UFE.config.player2Character);
            UFE.config.player2Character = myInfo;

            debugger = UFE.debugger2;
            mirror = 1;
            playerNum = 2;

            inputController = UFE.GetPlayer2Controller();
            debugInfo = UFE.config.debugOptions.p2DebugInfo;
        }

        myInfo.currentLifePoints = (float)myInfo.lifePoints;

        if (myInfo.characterPrefab == null)
            Debug.LogError("Character prefab for "+ gameObject.name +" not found. Make sure you have selected a prefab character in the Character Editor");

        character = (GameObject) Instantiate(myInfo.characterPrefab);
        character.transform.parent = transform;
        character.AddComponent<MoveSetScript>();

        standardYRotation = character.transform.rotation.eulerAngles.y;

        myPhysicsScript = GetComponent<PhysicsScript>();
        myMoveSetScript = character.GetComponent<MoveSetScript>();
        myHitBoxesScript = character.GetComponent<HitBoxesScript>();
        cameraScript = transform.parent.GetComponent<CameraScript>();

        myHitBoxesScript.controlsScript = this;

        if (myInfo.headLook.enabled){
            character.AddComponent<HeadLookScript>();
            headLookScript = character.GetComponent<HeadLookScript>();
            headLookScript.segments = myInfo.headLook.segments;
            headLookScript.nonAffectedJoints = myInfo.headLook.nonAffectedJoints;
            headLookScript.effect = myInfo.headLook.effect;
            headLookScript.overrideAnimation = !myInfo.headLook.overrideAnimation;

            foreach(BendingSegment segment in headLookScript.segments) {
                segment.firstTransform = myHitBoxesScript.GetTransform(segment.bodyPart).parent.transform;
                segment.lastTransform = myHitBoxesScript.GetTransform(segment.bodyPart);
            }

            foreach(NonAffectedJoints nonAffectedJoint in headLookScript.nonAffectedJoints)
                nonAffectedJoint.joint = myHitBoxesScript.GetTransform(nonAffectedJoint.bodyPart);
        }

        if (gameObject.name == "Player2") {
            testCharacterRotation(100, true);
            UFE.FireGameBegins();
        }

        if (UFE.config.roundOptions.allowMovement) {
            UFE.config.lockMovements = false;
        }else{
            UFE.config.lockMovements = true;
        }
    }
    public Vector2 Move(Vector2 delta, Vector2 sourcePusherLevel, int depthCount)
    {
        depthCount++;
        if (depthCount > 10)
        {
            return(new Vector2(0, 0));
        }
        else
        {
            //Move attempts to move in the x dimension and then the y
            //it only moves us as far as we can move, and returns however far that was

            float   direction        = 0;
            Vector2 amountLeftToMove = delta;
            Vector2 totalAmountMoved = new Vector2();

            List <RaycastHit2D> currentPushHits  = new List <RaycastHit2D>();
            List <RaycastHit2D> currentCarryHits = new List <RaycastHit2D>();

            List <MovementControllerScript> hitThingsXmcs = new List <MovementControllerScript>();
            List <MovementControllerScript> hitThingsYmcs = new List <MovementControllerScript>();

            for (int i = 0; i < numberOfPassengerMovementPasses; i++)
            {
                Vector2 amountMoved = new Vector2(0, 0);

                if (Mathf.Abs(amountLeftToMove.x) > 0)
                {
                    direction       = Mathf.Sign(amountLeftToMove.x);
                    currentPushHits = HorizontalRaycastHits(MIN_DISTANCE * direction);
                    RaycastHit2D closestHit = GetClosestHit(currentPushHits);
                    if (closestHit.transform != null)
                    {
                        MovementControllerScript mcs = closestHit.transform.gameObject.GetComponent <MovementControllerScript>();
                        if (mcs != null)
                        {
                            bool          shouldGetPushed = (mcs.pushableLevel.x < sourcePusherLevel.x);
                            PhysicsScript physicsScript   = mcs.GetComponent <PhysicsScript>();
                            if (physicsScript != null)
                            {
                                if (physicsScript.onGround == false || physicsScript.velocity.y > 0)
                                //this is a convulted way of checking if I'm in the air and therefore should be pushed
                                {
                                    shouldGetPushed = true;
                                }
                            }
                            if (shouldGetPushed)
                            {
                                hitThingsXmcs.Add(mcs);
                                mcs.Move(new Vector2(amountLeftToMove.x, 0), sourcePusherLevel, depthCount);
                            }
                        }
                    }

                    amountMoved.x = CalculateMoveX(amountLeftToMove);
                    List <GameObject> carryObjects = new List <GameObject>();

                    currentCarryHits = VerticalRaycastHits(MIN_DISTANCE);
                    foreach (RaycastHit2D hit in currentCarryHits)
                    {
                        if (hit.transform != null)
                        {
                            if (!carryObjects.Contains(hit.transform.gameObject))
                            {
                                if (hit.transform.gameObject.GetComponent <PhysicsScript>() != null)
                                {
                                    carryObjects.Add(hit.transform.gameObject);
                                }
                            }
                        }
                    }
                    if (carryObjects.Count > 0 && amountMoved.x != 0)
                    {
                        List <GameObject> carryObjectsSorted = SortGameObjectsByPositionX(carryObjects);

                        int iStart;
                        int iDirection;
                        int iEnd;
                        if (amountMoved.x < 0)
                        {
                            iStart     = 0;
                            iDirection = 1;
                            iEnd       = carryObjectsSorted.Count;
                        }
                        else
                        {
                            iStart     = carryObjectsSorted.Count - 1;
                            iDirection = -1;
                            iEnd       = -1;
                        }
                        for (int j = iStart; j != iEnd; j += iDirection)
                        {
                            GameObject carryObject       = carryObjectsSorted[j];
                            MovementControllerScript mcs = carryObject.GetComponent <MovementControllerScript>();
                            if (mcs != null)
                            {
                                if (!mcs.beenCarriedThisFrame)
                                {
                                    mcs.beenCarriedThisFrame = true;
                                    mcs.Move(new Vector2(amountMoved.x, 0));
                                }
                            }
                        }
                    }
                }

                TranslateAndRecord(amountMoved);
                if (Mathf.Abs(amountLeftToMove.y) > 0)
                {
                    direction       = Mathf.Sign(amountLeftToMove.y);
                    currentPushHits = VerticalRaycastHits(MIN_DISTANCE * direction);

                    List <GameObject> hitObjects = new List <GameObject>();
                    foreach (RaycastHit2D hit in currentPushHits)
                    {
                        if (hit.transform != null)
                        {
                            if (!hitObjects.Contains(hit.transform.gameObject))
                            {
                                hitObjects.Add(hit.transform.gameObject);
                            }
                        }
                    }
                    List <GameObject> pushedObjects = new List <GameObject>();
                    foreach (GameObject hitObject in hitObjects)
                    {
                        MovementControllerScript hitMCS = hitObject.GetComponent <MovementControllerScript>();
                        if (hitMCS != null)
                        {
                            if (hitMCS.pushableLevel.y < sourcePusherLevel.y)
                            {
                                if (!pushedObjects.Contains(hitMCS.gameObject))
                                {
                                    pushedObjects.Add(hitMCS.gameObject);
                                }
                            }
                        }
                    }

                    float   minDistanceMoved = Mathf.Infinity;
                    float[] distancesMoved   = new float[pushedObjects.Count];

                    for (int j = 0; j < pushedObjects.Count; j++)
                    {
                        GameObject pushedObject         = pushedObjects[j];
                        MovementControllerScript hitMCS = pushedObject.GetComponent <MovementControllerScript>();
                        distancesMoved[j] = hitMCS.Move(new Vector2(0, amountLeftToMove.y), sourcePusherLevel, depthCount).y;

                        if (distancesMoved[j] < minDistanceMoved)
                        {
                            minDistanceMoved = distancesMoved[j];
                        }
                    }

                    for (int j = 0; j < pushedObjects.Count; j++)
                    {
                        GameObject pushedObject = pushedObjects[j];
                        if (distancesMoved[j] > minDistanceMoved)
                        {
                            MovementControllerScript mcs = pushedObject.GetComponent <MovementControllerScript>();
                            if (mcs != null)
                            {
                                float diff = distancesMoved[j] - minDistanceMoved;
                                mcs.Move(new Vector2(0, diff * direction * -1));
                            }
                        }
                    }

                    List <GameObject> carryObjects = new List <GameObject>();

                    if (direction < 0)
                    {
                        currentCarryHits = VerticalRaycastHits(MIN_DISTANCE);
                        foreach (RaycastHit2D hit in currentCarryHits)
                        {
                            if (hit.transform != null)
                            {
                                if (!carryObjects.Contains(hit.transform.gameObject))
                                {
                                    carryObjects.Add(hit.transform.gameObject);
                                }
                            }
                        }
                    }

                    amountMoved.y = CalculateMoveY(amountLeftToMove);
                    TranslateAndRecord(new Vector2(0, amountMoved.y));
                    if (direction < 0)
                    {
                        foreach (GameObject carryObject in carryObjects)
                        {
                            MovementControllerScript mcs           = carryObject.GetComponent <MovementControllerScript>();
                            PhysicsScript            physicsScript = carryObject.GetComponent <PhysicsScript>();
                            //TODO: this is not the right way to prevent things from simultaneously pulling objects down and being pushed by them
                            if (physicsScript != null)
                            {
                                if (mcs.pushableLevel.y <= pusherLevel.y)
                                {
                                    mcs.Move(new Vector2(0, amountMoved.y));
                                }
                            }
                        }
                    }
                }
                amountLeftToMove -= amountMoved;
                totalAmountMoved += amountMoved;
            }
            return(totalAmountMoved);
        }
    }
Exemplo n.º 14
0
 // Use this for initialization
 void Start()
 {
     physicsScript = GetComponent <PhysicsScript>();
 }