Forum begins after the advertisement:


[Part 16] Axe Weapon Upward Velocity

Home Forums Video Game Tutorial Series Creating a Rogue-like Shoot-em Up in Unity [Part 16] Axe Weapon Upward Velocity

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #14642
    Nathan
    Participant

    Hello,
    I just worked on the axe weapon from part 16 and I’m having difficulties with the weapon being thrown up. At the moment the weapon spawns in and falls in whichever way the player is facing. I did some searching and using ChatGPT, I got some logic that will throw the axe upward(not very smooth) but I currently have that commented out because I wanted to see if I missed something or I’m misunderstanding the physics.
    Thank you

    #14643
    Terence
    Keymaster

    Hi Nathan, can you share your code for the AxeWeapon? If you’re able to get a video recording of the axe spawning, that will be great as well.

    #14646
    Nathan
    Participant

    Apologies, here you go.

    public class AxeWeapon : ProjectileWeapon
    {
        //gives the spawn angle when instantiated
        protected override float GetSpawnAngle()
        {
            //calculates offset that is used to modify the angle of axes
            int offset = currentAttackCount > 0 ? currentStats.number - currentAttackCount : 0;
            //instantiates the first projectile at 90 degrees and modifies future axes during attack
            return 90f - Mathf.Sign(movement.lastMovedVector.x) * (5 * offset); 
        }
    
        protected override Vector2 GetSpawnOffset(float spawnAngle = 0)
        {
            return new Vector2(
                Random.Range(currentStats.spawnVariance.xMin, currentStats.spawnVariance.xMax),
                Random.Range(currentStats.spawnVariance.yMin, currentStats.spawnVariance.yMax));
        }
    }
    

    View post on imgur.com

    #14647
    Terence
    Keymaster

    What is the Speed attribute of your Axe in the WeaponData file? Try increasing it and see if this fixes the issue.

    #14648
    Nathan
    Participant

    Ah, that was it. It was set to 1. Increasing it fixed it.
    Thank you

    View post on imgur.com

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

Go to Login Page →


Advertisement below: