TazGraph Project v0.1.0
Loading...
Searching...
No Matches
RigidBodyComponent.h
1#pragma once
2#include "../../../Components.h"
3
5{
6private:
7 TransformComponent* transform = nullptr;
8public:
9 float GravityForce = 1.0f;
10 float accelGravity = 0.045f;
11 float maxGravity = 3.f;
12 bool onGround = false;
13 bool justjumped = false;
14
15 RigidBodyComponent() = default;
16
17 RigidBodyComponent(float acc, float maxg)
18 {
19 accelGravity = acc;
20 maxGravity = maxg;
21 }
22
24 {
25
26 }
27
28 void init() override
29 {
30 transform = &entity->GetComponent<TransformComponent>();
31 }
32
33 void update(float deltaTime) override
34 {
35 if (onGround && !justjumped)
36 {
37 GravityForce = 1.0f;
38 transform->setVelocity_Y(GravityForce);
39 GravityForce = 0.0f;
40 }
41 else
42 {
43 justjumped = false;
44 GravityForce += accelGravity * deltaTime;
45 transform->setVelocity_Y(transform->getVelocity().y + GravityForce * deltaTime);
46 if (transform->getVelocity().y > maxGravity)
47 {
48 transform->setVelocity_Y(maxGravity);
49 }
50 }
51 }
52
53 std::string GetComponentName() override {
54 return "RigidBodyComponent";
55 }
56};
Definition GECS.h:123
Definition RigidBodyComponent.h:5
Definition TransformComponent.h:6