Hi playcanvas community, I am having a problem regarding rigidbodies so I need some help.
The thing is my player rigidbody is the only one not colliding with other entities, I can’t figure out what is causing this since I have done all the things I know.
This is because you have moved the player to 0 on the Z axis every frame when all the objects are on 0.2:
// Prevent player from moving out of screen and tilt when moving horizontally
const position = self.entity.getPosition();
const newPosition = new pc.Vec3(
pc.math.clamp(position.x, xMin, xMax),
pc.math.clamp(position.y, yMax, yMax),
0);
const newRotation = new pc.Vec3(0, 0, 0);
this.entity.setPosition(newPosition);
If you still want to use dynamic rigid body, then I would change this to only teleport the player if they have crossed the boundaries rather than clamping every frame.
Ok I’ll do that., one more issue I have is that whenever I leave the game tab and return to it after some time all the entities spawned during that absence comes at one with no regard to physics they are just shoved in each other or they flicker weirdly. I know the game has a lot of bugs, I am new to playcanvas and learning so it is kinda difficult dealing with them all at once.
That’s because of the game controller using realtime to spawn asteroids rather than using the engine’s deltatime in update that is ‘paused’ if the tab is not in focus.