Kinematic RigidBody Collision Triggers

hello! i’m very new to PlayCanvas. while making my 2D game, i’ve found that i much prefer the more 2D gameplay movement of Kinematic RigidBodies as opposed to Dynamic. however, i’m unable to make the player collide with walls and such. i found this thread: [SOLVED] How can I stop the player when it hit a block without using applyForce?

which brought to me the idea of using triggers for collision instead. i am trying to make my player collide with a rock for starters, however, it keeps telling me that “hitBlock is not defined.” i’ve tried defining it through var hitBlock = false; in the rock’s code, but i’m very sure that i’m making a mistake. i’ve also removed the RigidBody component in the rock but to no avail. is this collision trigger system really possible or am i just missing something? thank you, and much appreciated!

link to my project: PlayCanvas | HTML5 Game Engine

Hi @GAB_VILLAPANDO and welcome,

If you are using triggers then your collision event should be this:

this.entity.collision.on('triggerenter', this.onCollisionStart, this);

Check the documentation on the collision component here:
https://developer.playcanvas.com/api/pc.CollisionComponent.html

thanks for the suggestion! it seems now it’s recognizing and triggering each other. however, the trigger code isn’t executing for some reason and every time they collide, it just passes through with the error TypeError: result.other is undefined referring to my boolean, which i got from my previously linked thread and the Collision Tutorial.
i’ve been looking through the Tutorials and API and trying to follow along, but it seems like something’s still missing. your help is much appreciated :pray:

Hi @GAB_VILLAPANDO! For triggers it’s just result instead of result.other.

1 Like

thank you Albertos for the suggestion, but that just seems to make my character pass through the rock.

however, i’ve found an (albeit inelegant) solution to my problem without the need for triggers (but it does not use Kinematic Rigidbody like i originally wanted, sorry to those who lurk for an answer). it does look and feel like a Kinematic though!

it uses Dynamic Rigidbody like such
image
and an applyForce within the player’s WASD code
this.entity.rigidbody.applyForce(0, walkSpeed * dt, 0);
as well as a gravity code in the initialize code
this.app.systems.rigidbody.setGravity(0, gravity, 0);
with var’s up top in the same player’s movement code
var walkSpeed = 3000;
var gravity = 0;

the player does indeed walk abysmally slow unless you crank up the walkSpeed. shoutout to my friends who helped me figure this one out!!

1 Like