KinematicActor¶
A body that is moved manually via code but still interacts with the physics world.
Description¶
Kinematic actors are not affected by world gravity or forces but can detect and react to collisions during movement. They provide methods like moveAndSlide for complex character movement.
Note: Kinematic actors now correctly interact with RigidActors, pushing them aside when moving into them.
Namespace¶
Inheritance¶
- Base class: PhysicsActor
Constructors¶
-
KinematicActor(Scalar x, Scalar y, int w, int h)Constructs a new KinematicActor. -
KinematicActor(Vector2 position, int w, int h)Constructs a new KinematicActor using a position vector.
Public Methods¶
-
bool moveAndCollide(Vector2 motion, KinematicCollision* outCollision = nullptr, bool testOnly = false, Scalar safeMargin = 0.08f, bool recoveryAsCollision = false)Moves the body along a vector and stops at the first collision.motion: The movement vector.outCollision: Pointer to store collision information (optional).testOnly: If true, checks for collisions without moving the body.safeMargin: Extra margin used for collision recovery (default 0.08).recoveryAsCollision: If true, depenetration is reported as collision. Returns true if a collision occurred.
-
void moveAndSlide(Vector2 velocity, Vector2 upDirection = {0, -1})Moves the body while sliding along surfaces.velocity: The linear velocity vector (pixels/second) or displacement vector depending on usage.upDirection: Direction considered "up" for floor detection (default: 0, -1).
-
bool is_on_ceiling() constReturns true if the body collided with the ceiling during the lastmoveAndSlidecall. -
bool is_on_floor() constReturns true if the body collided with the floor during the lastmoveAndSlidecall. -
bool is_on_wall() constReturns true if the body collided with a wall during the lastmoveAndSlidecall. -
void draw(pixelroot32::graphics::Renderer& renderer)Draws the actor.