Struggling with Enemy Shove Mechanics in Unity

0
5
Asked By CodingNinja88 On

I'm developing an action platformer where I have two enemies so far: a sword fighter who rushes at the player and attacks, and an archer who I'm currently working on. The archer has an arrow system that works well, but I'm stuck on implementing a 'shove' mechanic. The idea is that if the player gets too close to the archer, it will shove the player back using its bow, preventing them from easily melee attacking. However, I've spent several days trying to get the shove mechanic to actually push the player back, and I'm not having any luck. I'm using Unity with C#, and I'd appreciate any help! Happy to provide more details about the code if needed. Thanks!

2 Answers

Answered By DevMaster42 On

You might want to take a look at your approach. I suggest calculating a vector that goes from the archer's position to the player's position, basically the 'away' direction. Then, normalize that vector to maintain consistent shove strength regardless of distance. After that, multiply the normalized vector by a 'shove_power' variable to control how strong the shove is. Finally, apply that vector either to the player's velocity or as an impulse to the player’s physics object. Adding a temporary stun effect might help too, so the player can't just attack the archer immediately after being shoved.

ArcheryFan101 -

Sounds like a good plan! Just to clarify, should I be concerned about friction messing with the shove? I've run into issues where ground friction kept my character from moving properly.

Answered By PixelPioneer On

Is your movement physics-driven? You might be missing a rigidbody component or collider on the archer, which could affect how the shove interacts with the player.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.