private void Movement()
 {
     movementSpeed = Mathf.Clamp(movementSpeed, minMovementSpeed, maxMovementSpeed);
     if (Input.GetAxis("Horizontal") == 0)
     {
         walkTime        = 0f;
         movementSpeed   = minMovementSpeed;
         animationStance = AnimationStance.idle;
     }
     else
     {
         transform.Translate(Vector3.right * Time.deltaTime * movementSpeed);
         walkTime += Time.deltaTime;
         if (walkTime > 1f)
         {
             movementSpeed += 0.08f;
         }
         else
         {
             movementSpeed = minMovementSpeed;
         }
         animationStance = AnimationStance.walk;
         FlipSpriteRotation();
     }
 }
 private void Jump()
 {
     isGrounded = Physics2D.OverlapCircle(groundDetector.position, 1F, whatIsGrounded);
     if (isGrounded && Input.GetButtonDown("Jump"))
     {
         rb2d.velocity   = Vector2.up * jumpVelocity;
         animationStance = AnimationStance.jump;
     }
     if (rb2d.velocity.y > 0 && !Input.GetButton("Jump"))
     {
         rb2d.velocity  += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1) * Time.deltaTime;
         animationStance = AnimationStance.jump;
     }
     if (rb2d.velocity.y < 0)
     {
         rb2d.velocity  += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
         animationStance = AnimationStance.land;
     }
 }
Esempio n. 3
0
    private void Movement()
    {
        movementSpeed = Mathf.Clamp(movementSpeed, minMovementSpeed, maxMovementSpeed);
        if (playerHit.collider != null)
        {
            if (playerHit.collider.gameObject.layer == 9 && playerHit.distance < 0.1f && objectHit.distance < 0.1f || playerHit.collider.gameObject.layer != 9 && playerHit.distance < 0.1f)
            {
                if (rb2d.transform.forward.z > 0 && Input.GetAxis("Horizontal") > 0 || rb2d.transform.forward.z < 0 && Input.GetAxis("Horizontal") < 0)
                {
                    walkTime        = 0f;
                    movementSpeed   = minMovementSpeed;
                    animationStance = AnimationStance.idle;
                    return;
                }
            }
        }
        if (Input.GetAxis("Horizontal") == 0)
        {
            walkTime        = 0f;
            movementSpeed   = minMovementSpeed;
            animationStance = AnimationStance.idle;
        }
        else
        {
            transform.Translate(Vector3.right * Time.deltaTime * movementSpeed);


            audioManager.PlaySound("walk");


            walkTime += Time.deltaTime;
            if (walkTime > 1f)
            {
                movementSpeed += 0.085f;
            }
            else
            {
                movementSpeed = minMovementSpeed;
            }
            animationStance = AnimationStance.walk;
        }
    }
        public Hero(int health, int maxHealth, ref Model modelwalk, ref Model  modeldie, ref Model modelhurt, Action<Entity, Entity> actionFunction)
            : base()
        {
            this.model = modelwalk;
            this.HealthPoints = health;
            this.MaxHealth = maxHealth;
            this.Stance = AnimationStance.Standing;

            PowerupsList = new List<Powerup>();
            ItemsList = new Dictionary<Item, int>();
            WeaponsList = new Dictionary<Weapon, int>();
            this.ActionFunction = actionFunction;

            //get animations
            // Look up our custom skinning information. for walking

            skinningDatawalk = (SkinningData)modelwalk.Tag;

            if (skinningDatawalk == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag.");

            // Create an animation player, and start decoding an animation clip.
            animationPlayerwalk = new AnimationPlayer(skinningDatawalk);
            clipwalk = skinningDatawalk.AnimationClips["Take 001"];
            animationPlayerwalk.StartClip(clipwalk);

            // Look up our custom skinning information. for dying
            skinningDatadie = (SkinningData)modeldie.Tag;

            if (skinningDatadie == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag.");

            // Create an animation player, and start decoding an animation clip.
            animationPlayerdie = new AnimationPlayer(skinningDatadie);
            clipdie = skinningDatadie.AnimationClips["Take 001"];
            animationPlayerdie.StartClip(clipdie);

            // Look up our custom skinning information. for hurting
            skinningDatahurt = (SkinningData)modelhurt.Tag;

            if (skinningDatahurt == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag.");

            // Create an animation player, and start decoding an animation clip.
            animationPlayerhurt = new AnimationPlayer(skinningDatahurt);
            cliphurt = skinningDatahurt.AnimationClips["Take 001"];
            animationPlayerhurt.StartClip(cliphurt);

            //adding flanking info
            for (int i = 0; i < 6; i++)
            {
                slots[i] = new Node();
            }
        }
Esempio n. 5
0
        public Hero(int health, int maxHealth, ref Model modelwalk, ref Model modeldie, ref Model modelhurt, Action <Entity, Entity> actionFunction)
            : base()
        {
            this.model        = modelwalk;
            this.HealthPoints = health;
            this.MaxHealth    = maxHealth;
            this.Stance       = AnimationStance.Standing;

            PowerupsList        = new List <Powerup>();
            ItemsList           = new Dictionary <Item, int>();
            WeaponsList         = new Dictionary <Weapon, int>();
            this.ActionFunction = actionFunction;

            //get animations
            // Look up our custom skinning information. for walking

            skinningDatawalk = (SkinningData)modelwalk.Tag;

            if (skinningDatawalk == null)
            {
                throw new InvalidOperationException
                          ("This model does not contain a SkinningData tag.");
            }

            // Create an animation player, and start decoding an animation clip.
            animationPlayerwalk = new AnimationPlayer(skinningDatawalk);
            clipwalk            = skinningDatawalk.AnimationClips["Take 001"];
            animationPlayerwalk.StartClip(clipwalk);

            // Look up our custom skinning information. for dying
            skinningDatadie = (SkinningData)modeldie.Tag;

            if (skinningDatadie == null)
            {
                throw new InvalidOperationException
                          ("This model does not contain a SkinningData tag.");
            }

            // Create an animation player, and start decoding an animation clip.
            animationPlayerdie = new AnimationPlayer(skinningDatadie);
            clipdie            = skinningDatadie.AnimationClips["Take 001"];
            animationPlayerdie.StartClip(clipdie);

            // Look up our custom skinning information. for hurting
            skinningDatahurt = (SkinningData)modelhurt.Tag;

            if (skinningDatahurt == null)
            {
                throw new InvalidOperationException
                          ("This model does not contain a SkinningData tag.");
            }

            // Create an animation player, and start decoding an animation clip.
            animationPlayerhurt = new AnimationPlayer(skinningDatahurt);
            cliphurt            = skinningDatahurt.AnimationClips["Take 001"];
            animationPlayerhurt.StartClip(cliphurt);

            //adding flanking info
            for (int i = 0; i < 6; i++)
            {
                slots[i] = new Node();
            }
        }