Exception when using the p2.js physics engine

on launching it is giving error a is null


That’s not the error I’m seeing:

But it is showing in mine

One major problem here is that you haven’t created a physics world. On your root entity, create a script component and then create a p2World script on it.

1 Like

I see. Thank you

1 Like

Now the vehicle falls right through the plane. Do i have to make the plane a rigid body?

It’s because:

  1. You have the Physics World set to the XY plane. Your game is in the XZ plane. So use that.
  2. You have gravity set to [0, -9.8]. But for your game. you don’t want gravity so set it to [0, 0].

These are the World settings in my screenshot further up (taken from the car demo in the p2.js integration project).

Oh, now i get it. Really appreciate your help. One more thing, where is the option to change default position of car? I can see that the position changes once the game starts.

I’m not sure I understand the question. By ‘default position of car’ do you mean the place where the car starts? That should be the same place as in the Editor.

What i meant is on applying p2 script the components orientation change during launch like following picture. It happens either through p2Box or p2Body, not sure which one.

I added p2Box and p2Body to fences. Now it is completely displaced