Soon I will be trying to implement melee damage for my NPC against the player. I am just curious how other Urho3d users have gone about this.
Thanks
Soon I will be trying to implement melee damage for my NPC against the player. I am just curious how other Urho3d users have gone about this.
Thanks
It depends a bit on the exact situation and what you already have. Is there something that stores health or do you even have ranged attacks already implemented?
And by melee, do you mean colliding with the enemy, something more akin to a swinging sword or a (delayed) distance check?
I mean a sword colliding with a node and a set damage is deducted from the health amount. I have it where the NPC is within a certain range of the player the NPC will swipe at the player. Nothing really fancy at this moment.
Part of the sword/enemy FixedUpdate function could include a physics swipe (similar to casting a ray) covering the area it passed through in the current frame. The component keeping track of health could then be retrieved through the rigid body node with functions like Node::HasComponent<T>()
, Node::GetComponent<T>()
, Node::GetDerivedComponent<T>()
and similar functions (see Node.h). Then you could call Destructable::Hit(damage)
or something of the sort, depending on your exact implementation.
Sounds like a good idea. I need to dig around and see. I will post back later. Thanks
@Modanung Do you have any more info on the swipe idea?
I think using a PhysicsWorld::ConvexCast
- or multiple raycasts - would make most sense.
/// Perform a physics world swept convex test using a user-supplied collision shape and return the first hit.
void ConvexCast(PhysicsRaycastResult& result, CollisionShape* shape, const Vector3& startPos, const Quaternion& startRot, const Vector3& endPos, const Quaternion& endRot, unsigned collisionMask = M_MAX_UNSIGNED);
/// Perform a physics world raycast and return all hits.
void Raycast(PODVector<PhysicsRaycastResult>& result, const Ray& ray, float maxDistance, unsigned collisionMask = M_MAX_UNSIGNED);
Do you have experience with physics raycasting? A demonstration of this can be found in the inverse kinematics sample (45).
Perhaps, use physics collision object instead of raycast
This would require one of the bodies to be a trigger, right? To prevent - likely unwelcome - forces from being applied. RigidBody::SetTrigger(true)
As Bullet expects triggers to be stationary, wouldn’t this introduce the risk of the blade passing through objects unnoticed? Especially at low frame rates.
With a convex cast a collision mask could be used to single out relevant targets.
@Modanung I don’t care if the sword passes through the player or against another NPC as long as the damage and other things still work.
But it should not pass through the player and ignore this fact, right?
I mean I guess it depends on the approach right? If I use the sword as an actual physics mesh then I guess not. I’m just saying it does not have to be that precise unless your saying with your approach that it needs to behave this way than that’s fine.
If neither of both the bodies involved is a trigger - and their layers and masks overlap - one will not be able to pass through the other and you should only apply forces to make them move, refraining from setting positions and velocities directly. That includes no attribute animations. This to not mess up the physics simulation.
So what approach do you recommend? Yours or Lumak?
I am hoping @Lumak can convincingly refute or confirm my statements.
Until then I’d do it my way.
Well let me go look at sample 45.
Other samples that utilize physics raycasting - to position the camera - are 18, 19 and 46.
You might also look into a Bullet Ghost Object. This thread has a bit of discussion about one, though there may be a couple other threads as well (and also search engines).
What are the benefits of the ghost object method?
Bullet does not expect them to be stationary, yet objects pass through them. As such they are ideal for this situation and - like convex casting - would not suffer the risk that moving triggers do.
Okay. Time to try and understand his post on Ghost Objects.
I think I might try Raycast first. I have not done anything real fancy with the Physics part of Urho3d.