-
Notifications
You must be signed in to change notification settings - Fork 0
physics::collider
Paweł Waligóra edited this page Apr 25, 2024
·
9 revisions
This class serves as a base class for:
You should not use physics::collider
but rather one of the above instead.
physics::collider
has 3 subscription lists:
- on_collision_enter
- on_collision_stay
- on_collision_exit
Declare collider in a script scope.
Construct it's object with right parameters.
Subscribe to it's collision events lists or use it as a collider for rigidbody.
example below shows how to use collider in a script as an event trigger as well as a collider for a rigidbody
#pragma once
#include <physics.h>
#include <scripts_system.h>
namespace game {
class player : public scripts_system::script {
public:
player();
// ...
private:
void jump();
void land(physics::collision_info ci);
physics::rigidbody rb; // if you want to use collider just for triggering events - skip the rigidbody
physics::colliders::sphere col;
float jump_force = 5.5f; // actually velocity [m/s]
bool ready_to_jump = false;
// ...
};
}
game::player::player() : rb(), col(&rb, 1.5f) { // pass rigidbody to collider as constructor parameter
rb.force = physics::gravity * rb.mass;
// subscribe for collision event
col.on_collision_enter.subscribe(std::bind(&game::player::land, this, std::placeholders::_1));
}
void game::player::jump()
{
if (ready_to_jump) {
ready_to_jump = false;
rb.velocity.y += jump_force;
}
}
void game::player::land(physics::collision_info ci) { // this will be called when collider enters a collision with any other collider
if (!ready_to_jump) {
ready_to_jump = true;
}
}
- engine
- scripts_system
- scene_loader
- time_system
-
input_system
- input_system::key_held
- input_system::key_events
- input_system::subscribe() (deprecated)
- input_system::axis_state()
- input_system::key_bind
- input_system::axis
- input_system::double_axis
- input_system::triple_axis
- input_system::axis2
- input_system::double_axis2
- input_system::triple_axis2
- input_system::axis-choice
- renderer
- physics
- ui_system
- game