Forum begins after the advertisement:


[Part 3] Slash effect doesn’s stretch to fit attack area

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 3] Slash effect doesn’s stretch to fit attack area

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #13939
    claudio bramante
    Participant

    Hi, I have a trouble on part 3.
    As the title suggests, the slash effect is not stretched to fill the attack area but only moves, the size of the effect remains the same regardless of the size of the attack area I enter in the inspector.
    I followed the tutorial step by step and it seems like I didn’t do anything wrong
    Below are script and videos:

    void Attack()
    {
    timeSinceAttack += Time.deltaTime;
    if (attack && timeSinceAttack >= timeBetweenAttack)
    {
    timeSinceAttack = 0;
    anim.SetTrigger(“Attacking”);

    if (yAxis < 0.5 && yAxis > -0.5 || yAxis <= -0.5 && Grounded())
    {
    Hit(SideAttackTransform, SideAttackArea, ref pState.recoilingX, recoilXSpeed);
    Instantiate(slashEffect, SideAttackTransform);
    }
    else if(yAxis >= 0.5)
    {
    Hit(UpAttackTransform, UpAttackArea, ref pState.recoilingY, recoilYSpeed);
    SlashEffectAtAngle(slashEffect, 90, UpAttackTransform);
    }
    else if (yAxis <= -0.5 && !Grounded())
    {
    Hit(DownAttackTransform, DownAttackArea, ref pState.recoilingY, recoilYSpeed);
    SlashEffectAtAngle(slashEffect, -90, DownAttackTransform);
    }
    }
    }

    void SlashEffectAtAngle(GameObject _slashEffect, int _effectAngle, Transform _attackTransform)
    {
    _slashEffect = Instantiate(_slashEffect, _attackTransform);
    _slashEffect.transform.eulerAngles = new Vector3(0, 0, _effectAngle);
    _slashEffect.transform.localScale = new Vector2(transform.localScale.x, transform.localScale.y);
    }

    View post on imgur.com

    #13941
    Joseph Tang
    Moderator

    Sorry for the confusion, however, the gizmos drawn are only hitbox indicators that you adjust to the size of your slash effect and not the other way around. The only aspects of the slash effect that are influenced by the code are the position and angle of the effect.

    In other words, you do not control how big the slash effect is through the PlayerController.cs.

    If you want to change your attack range, you will have to change the scale of the “Slash Effect” Prefab you are using, then adjust the size of your Gizmos & position of your attack transforms accordingly.

    #13944
    claudio bramante
    Participant

    sorry, watching the video I understood that the effect was scaled accordingly to the attack area, now everything is clearer

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: