-
Notifications
You must be signed in to change notification settings - Fork 0
/
EfectDamageOnCollision.cpp
46 lines (32 loc) · 1.43 KB
/
EfectDamageOnCollision.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "EfectDamageOnCollision.h"
#include <limits>
EfectDamageOnCollision::EfectDamageOnCollision(float _flatDamage, float _springDamage, float _maxSpring)
:flatDamage(_flatDamage), springDamage(_springDamage), maxSpring(_maxSpring)
{
}
void EfectDamageOnCollision::onCollision(const ColliderInfo& otherCollider)
{
Efect::onCollision(otherCollider);
if (otherCollider.efect != nullptr)
{
Vector2D toOther = otherCollider.getActualCollider().center - colliderInfo->getActualCollider().center;
float force = flatDamage;
if (!toOther.isZero() && springDamage*springDamage > numeric_limits<float>::min() )
{
// prepare toOther to being an inverse vector
toOther *= (colliderInfo->collider.range + otherCollider.collider.range) / toOther.getLenghtSq();
// check is the vector in proper range
if (toOther.getLenghtSq() > maxSpring*maxSpring/(springDamage*springDamage))
{
toOther = toOther.normalised() * maxSpring/springDamage;
}
force += toOther.getLenght()*springDamage;
//cout << "toOther: " << toOther.getLenght() << "\n";
}
//cout << "dmg: " << force << "\n";
otherCollider.efect->onDamage(force);
//Vector2D v = getOwner()->getPosC().velocity - otherCollider.efect->getPosC().velocity;
//otherCollider.efect->onDamage(flatDamage + v.getLenght() * velocityDamage, getOwner());
//cout << "dmg: " << flatDamage + v.getLenght() * velocityDamage << "\n";
}
}