Adding Special Enemies + Basic Projectile Motion Implementation | Dev Log#2
Cassandra of the Far North East » Devlog
So I added some new stuff on my game like having arrows accurately hit the player at any given distance or height and special enemies with scriptable objects as one of the components I will be using for states. I'll just talk about implementing the projectile motion implementation in here, because I feel like I wasn't clear enough in the video.
So, the reason for doing this is because I only have one basic attack animation of the archer shooting horizontally, but I still wanted it to reach the player regardless of the height and distance of the enemy:
- Of course, we do not just want the arrow to home on the player, we want it to reach the player like what an actual arrow does in real life. First, I look for what value I actually need for my projectile to reach the player, so remember that we are just shooting horizontally, that means that we are only shooting on the x axis not y axis this means that Velocity for our projectile in the y axis would be equal to 0:
- This would be the formula that we would be using in our implementation:
- If you look at the formula the only thing we are missing, is the elapsed time projectile is in the air so in order to find that we will be using another formula in kinematics to find time:
- Arranging this for time we get:
- Putting all this together in my code it would be:
- Now for the final touch we are going plugin the velX in Rigid Body component and we will also calculate the acceleration in the y axis to plugin in the Rigid Body as well:
- With this all done we finally have an enemy that can shoot the player accurately, regardless of the height, and distance of the player(this only applies as long as the player is not higher done the enemy as the acceleration in the y axis is always negative in this case):
That's all for this dev log thanks for tuning in!
Checkout my other socials here: linktr.ee/mmr_games
Cassandra of the Far North East
A simple game about Cassandra's adventure in the land of the Far North East.
Status | In development |
Author | MMR |
Genre | Adventure, Platformer, Role Playing, Survival |
Tags | Boss battle, Dark Fantasy, Fantasy, Pixel Art, Side Scroller, Unity |
More posts
- New Pathfinding System for my Enemies | Dev Log#3Jun 12, 2024
- Enemy Skills | Dev Log# 1Apr 28, 2024
- Enemies| Dev. Log#0Apr 24, 2024
Leave a comment
Log in with itch.io to leave a comment.