Forum begins after the advertisement:


[Part 3] Zombie falling slowly

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 3] Zombie falling slowly

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #13681
    Joseph Taylor
    Participant

    When I initially run my program my player and enemy fall a few inches since I have them start a bit higher then my ground. When I have just the enemy script on my enemy it runs fine. When I remove the enemy script and replace it with the Zombie script it seems as though gravity no longer has an affect on the enemy cube and it lightly floats down to chase the player. I can see in the inspector that the gravity scale gets changed to 12 like our Zombie Start method tells it to yet this seems to make no difference. All of my scripts match what is shown here:

    Creating a Metroidvania (like Hollow Knight) — Part 3: Melee combat & Enemy AI Base Class

    I do have the following warning in my console:
    Assets\Scripts\Zombie.cs(8,10): warning CS0114: ‘Zombie.Start()’ hides inherited member ‘Enemy.Start()’. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.

    Thanks in advance!

    #13682
    Terence
    Keymaster

    Does it still happen if you remove the Update() function on the Zombie script?

    I do have the following warning in my console:
    Assets\Scripts\Zombie.cs(8,10): warning CS0114: ‘Zombie.Start()’ hides inherited member ‘Enemy.Start()’. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.

    I don’t think this will cause any issue, because Enemy.Start() is empty, but you can change the Start() function to protected override void Start() and this will fix the issue.

    @Joseph Tang, any thoughts?

    #13684
    Joseph Tang
    Moderator

    After Testing it out, I can confirm that all your code needs is for the Zombie.cs to inherit a rb = GetComponent<RigidBody2D>(); through either base.Awake() or base.Start() in your Zombie.cs, for the Gravity scale to change.

    As for the fact that despite the gravity scale, the enemy is not falling at the right speed. I can’t say that I know why it’s happening, as in my testing with the scripts in Part 3, it seems to work fine.

    The error code you get is simply asking you to put protected override void Start() as your inherited Enemy.cs has it’s own Start() method that clashes with the one you have in your Zombie.cs. Putting override will let you change the method without causing more errors from occuring, but you will need to include base.Start() if you want to use the code in the Enemy.cs Start() in your Zombie.cs.

    Also, in Part 6, we have created different scripts for 3 kinds of enemy types that you could encounter, removing and redoing the Zombie script into a different script.

    The most I can advise is to check if gravity scale is the issue (not working) by commenting out your Zombie’s movement code. If it falls normally or slowly. If it still falls slowly at a 12 gravity scale in the inspector, there must be an issue with your physics system, or an issue that’s not related to your movement codes. Otherwise, it might be the movement code that’s the issue.

    #13700
    Joseph Taylor
    Participant

    Hi Terence and Joseph, thanks for the speedy replies! Thanks for the info on Start(), you are absolutely right on that.

    I was able to discern that the gravity itself is not the issue. Thanks to your suggestion of commenting out the Zombie’s movement code I can see that the 2D sprite gravity scale gets set to the correct number and it falls as intended. Not sure why when I input the following code it seems to break this.
    if(!isRecoiling)
    {
    transform.position = Vector2.MoveTowards
    (transform.position, new Vector2(PlayerController.Instance.transform.position.x, transform.position.y),
    speed * Time.deltaTime);
    }

    Any further troubleshooting suggestions would be greatly appreciated! In the mean time, I will continue along your tutorial series. Thanks again for all the help!

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

Go to Login Page →


Advertisement below: