-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputComponent.cpp
More file actions
37 lines (31 loc) · 768 Bytes
/
Copy pathInputComponent.cpp
File metadata and controls
37 lines (31 loc) · 768 Bytes
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
#include "InputComponent.h"
#include "Math.h"
#include <iostream>
#include "Actor.h"
InputComponent::InputComponent(Actor* actor) : MoveComponent(actor)
,mMaxAngularSpeed(Math::Pi)
{
}
void InputComponent::ProcessInput(const uint8_t* keyState)
{
// calculate the forward speed of movecomponent
if (keyState[mForwardKey])
{
if (GetVelocity().Length() < (mOwner->GetForward()*GetMaxVelocity()).Length())
{
float mag = 80.0f;
Vector2 forward = mOwner->GetForward();
AddForce(forward * mag);
}
}
float angularSpeed = 0.0f;
if (keyState[mClockwiseKey])
{
angularSpeed += mMaxAngularSpeed;
}
if (keyState[mCounterClockwiseKey])
{
angularSpeed -= mMaxAngularSpeed;
}
SetAngularSpeed(angularSpeed);
}