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
- This topic has 3 replies, 3 voices, and was last updated 7 months ago by Joseph Taylor.
-
AuthorPosts
-
April 2, 2024 at 4:48 am #13681Joseph TaylorParticipant::
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!
April 2, 2024 at 11:46 am #13682TerenceKeymaster::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 theStart()
function toprotected override void Start()
and this will fix the issue.@Joseph Tang, any thoughts?
April 2, 2024 at 12:36 pm #13684Joseph TangModerator::After Testing it out, I can confirm that all your code needs is for the Zombie.cs to inherit a
rb = GetComponent<RigidBody2D>();
through eitherbase.Awake()
orbase.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 ownStart()
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 includebase.Start()
if you want to use the code in the Enemy.csStart()
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.
April 3, 2024 at 5:59 am #13700Joseph TaylorParticipant::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!
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: