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
- This topic has 2 replies, 2 voices, and was last updated 2 years ago by
claudio bramante.
-
AuthorPosts
-
April 18, 2024 at 4:53 am #13939::
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
April 18, 2024 at 11:45 am #13941::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.
April 18, 2024 at 1:41 pm #13944::sorry, watching the video I understood that the effect was scaled accordingly to the attack area, now everything is clearer
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: