-
Notifications
You must be signed in to change notification settings - Fork 4
/
BallMove.cpp
45 lines (39 loc) · 1.08 KB
/
BallMove.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
// Ahmed S. Tolba 2015-2018
#include "BallMove.h"
#include "Actor.h"
#include "Game.h"
#include "PhysWorld.h"
#include "TargetActor.h"
#include "BallActor.h"
BallMove::BallMove(Actor* owner)
:MoveComponent(owner)
{
}
void BallMove::Update(float deltaTime)
{
// Construct segment in direction of travel
const float segmentLength = 30.0f;
Vector3 start = mOwner->GetPosition();
Vector3 dir = mOwner->GetForward();
Vector3 end = start + dir * segmentLength;
// Create line segment
LineSegment l(start, end);
// Test segment vs world
PhysWorld* phys = mOwner->GetGame()->GetPhysWorld();
PhysWorld::CollisionInfo info;
// (Don't collide vs player)
if (phys->SegmentCast(l, info) && info.mActor != mPlayer)
{
// If we collided, reflect the ball about the normal
dir = Vector3::Reflect(dir, info.mNormal);
mOwner->RotateToNewForward(dir);
// Did we hit a target?
TargetActor* target = dynamic_cast<TargetActor*>(info.mActor);
if (target)
{
static_cast<BallActor*>(mOwner)->HitTarget();
}
}
// Base class update moves based on forward speed
MoveComponent::Update(deltaTime);
}