[SOLVED] entity.LookAt has a weird "flickering" issue when looking at my rigidbody

Hello!

I’m trying to build a physics-based car, using raycast wheels and applyForce. And to better look at what my car is doing I created a simple script that lets a camera look at the car.

Lookat.prototype.update = function(dt) {

    const position = this.car.getPosition();
    this.entity.lookAt(position);
    
    console.log( "car position: " + position );
};

Now this works fine-ish, it follows the car like it’s supposed to.

However every now and then the camera flickers for a frame as if it’s suddenly looking at something else. And other times it looks a completely random direction for multiple seconds, before looking back at the car.

Project: PlayCanvas 3D HTML5 Game Engine

The issue happens in the scene called “Car”

You can control the car by pressing arrow up and arrow down. You can’t steer yet. The glitchy lookat should start happening within a few seconds of moving the car around.

I also made a video to showcase the issue: my car is broken - YouTube Especially towards the end it becomes really apparent.

I’m stumped!

I only have one camera in the scene, and I don’t feel like I’m doing anything weird at all.

Does anyone know what I’m doing wrong?

Thanks!

  • Yannic

Hi @Yannic and welcome!

This is probably because you update the camera entity at the same time as the car entity. It seems that if you do your camera lookAt logic in the postUpdate function instead of the update function, everthing works smoothly.

Hello & thank you!

That works perfectly, thanks so much :smiley:

1 Like