Everything is working so far, except the player is not colliding with our obstacle.
Our obstacle also should be respawning along with the ground in random locations.
Here is the editor link https://playcanvas.com/editor/scene/2187919
Thanks for the help! I am working with a class of students trying to get our game going.
TLDR, you are trying to move a physics object by setting position but the physics type is dynamic.
This means it can only be moved by forces (see RigidBodyComponent | Engine API Reference - v2.6.2)
What is probably happening here is that because the physics object is a asleep, internally in the engine, it’s not syncing the entity with the collider position/rotation in the physics simulation. So it looks like it is moving, but in the physics simulation it isn’t.
TLDR, change the physics type to kinematic
Actually, I’m not sure you need the obstacle to be a rigid body at all. It looks like you want it to be a trigger instead so remove the rigidbody component and listen for trigger events
thank you. Removing the Rigid body still did not trigger a hit.
Changing it to kinematic did have the obstacle react to the collision but not with the hit animation.
I feel like it needs a more drastic change then a few changes. I see if I get some time to do a fork
I’ve made some fixes to get you going again.
I’ve removed some extra physics components that weren’t needed are were potentially causing issues and updated the code in obstacles.js
Project: PlayCanvas 3D HTML5 Game Engine
Editor changes:
Thank you! When I tried to make the same changes on our fork, We are getting this error.
this.entity.collision.on(pc.CollisionComponent.EVENT_TRIGGERENTER, this.onTriggerEnter, this);
after removing the rigidbody from barriersmall
https://playcanvas.com/editor/scene/2200374
The error occurs because an entity with the script doesn’t have a collision component, while you’re trying to access it using this.entity.collision
.
thank you!
So now moving forward, if I added more obstacles, with the same functions. I can make a duplicate template for obstacles?