mirror of
https://github.com/zoriya/Twac.git
synced 2026-05-28 17:03:13 +00:00
Adding realistic physics to the jump
This commit is contained in:
+1
-1
Submodule lib/gamacon updated: a15371fed1...b5b64a2f82
@@ -12,7 +12,7 @@
|
||||
<gravity_component speed="2000" />
|
||||
<keyboard_controller left="16" right="3" jump="57" />
|
||||
<walk_action acceleration="3000" max_acceleration="100" decceleration="100"/>
|
||||
<jump_action acceleration="7000" counterforce="6000"/>
|
||||
<jump_action acceleration="50000" counterforce="6000"/>
|
||||
<friction_component value=".7" />
|
||||
<collision_component layer="11000000" />
|
||||
</gc_entity>
|
||||
|
||||
@@ -23,16 +23,7 @@ gc_entity *entity, float dtime)
|
||||
struct movable_component *mov = GETCMP(movable_component);
|
||||
struct collision_component *col = GETCMP(collision_component);
|
||||
|
||||
if (mov->acceleration.y > -grav->gravity_speed) {
|
||||
if (mov->acceleration.y > 0)
|
||||
mov->acceleration.y -= grav->gravity_speed;
|
||||
else
|
||||
mov->acceleration.y = -grav->gravity_speed;
|
||||
}
|
||||
if (mov->acceleration.y < 0 && col->distance_down == 0) {
|
||||
mov->acceleration.y = 0;
|
||||
mov->velocity.y = 0;
|
||||
}
|
||||
mov->acceleration.y -= grav->gravity_speed;
|
||||
(void)system;
|
||||
(void)dtime;
|
||||
(void)engine;
|
||||
|
||||
@@ -30,7 +30,8 @@ gc_entity *entity, float dtime)
|
||||
jump->contered = false;
|
||||
} else if (!jump->contered && mov->acceleration.y > 0 && !con->jumping) {
|
||||
jump->contered = true;
|
||||
mov->acceleration.y = MAX(mov->acceleration.y - jump->counterforce, 0);
|
||||
if (mov->acceleration.y > 0)
|
||||
mov->acceleration.y -= MIN(jump->counterforce, mov->acceleration.y);
|
||||
}
|
||||
(void)system;
|
||||
(void)dtime;
|
||||
|
||||
Reference in New Issue
Block a user