Answer the question
In order to leave comments, you need to log in
How to do damage boost?
I want to make the character bounce from damage, but I don’t know how.
What exactly do I want to get: so that if a bullet flies into the character or an NPC crashes, he bounces back from the bullet or NPC, and if he flies in the back, then in front.
It turns out that the player bounces back from the position where he looks, and I want to make it so that even if he looks back and a bullet flies into him from behind, he bounces in front and not back.
Answer the question
In order to leave comments, you need to log in
I suppose you need to take the bullet's flight vector, i.e. build a vector yourself, and already repel the player to a new vector only less.
Well, apparently, at the OnCollisionEnter event, it sends some contacts, that is, contact points, each of them has a normal. If this is what I think, namely the unit vector. Then we add to the coordinates of the acceleration of the object, this normal multiplied by some number. The larger this number, the farther the object will fly off, I think the normal can be taken from the first point of contact. Type
var force = 5;
obj.velocity.x += collision.contacts[0].normal.x * force;
obj.velocity.y += collision.contacts[0].normal.y * force;
obj.velocity.z += collision.contacts[0].normal.z * force;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question