When I use Ammo.js,How Can i use collider event?


#1

I use vehicle.js to control my car,but ,I am not pleased with the effect of the Collision;so I want to do some function in the collider event ;
normally,i use event of CollisionComponent,like this:
this.entity.collision.on(“collisionStart” ,myfunction())

Now,there is no CollisionComponent to use for me !
so,how can i use collision event???
thank you !
I’m from china…


#2

It’s a bit difficult to tell without seeing the entity setup. If the car has physics, it should have a collision component on it somewhere. You will need to access it and listen for the events on it.

Can you share the project?


#3

Yes, I can share the project ,but ,I don’t know how to share it …
wait a moment,I search the way to share!


#4

tell me how to share it…


#5

I use the Ammo.js to create shape to collision,so ,I didn’t use the type of the collision!


#6

If the project is public, then you can just post the URL of the overview page here. For example: https://playcanvas.com/project/604437/overview/example-ui-button


#7

https://playcanvas.com/project/598370/overview/my-first-project
so easy…


#8

click right arrow button or left arrow button to control the motion of car


#9

Right now, your adjust script is not attached to any entity.

I’m not sure what problem you are having right now?


#10

Adjust .js is not useful ,so ,you don’t have a care on it;
I want to use collide event in my scripts, example :in my MyVehicle.js, to use a event ,OncolliderStart ;
The shape of Collision is not usefor,because I use Ammo.js to create shape instread of collisioncomponent


#11

The collider event only fires from the collider component. So you MUST have reference to the collider component object to listen to.

The collider component is using Ammo.js under the hood and must have a shape.

Maybe it be easier if you tell us what exactly you want to do with this event? Do you want to know if the vehicle hits something for example?


#13

I hope that the car get a stronger collisiion from the barrier ,I hope that after the car hit from the barrier,it can be flick far away.
so I want to give the car a stronger impluse force
I want to get the point of the hit on the wall from the collider event;
As you can see,in my MyVehicle.js , I use Ammo.js to create the shape, not use the type of collisioncomponent


#14

At the moment, the Tank already has a rigidBody and and collision component so they will collide with other rigidBodies regardless:

Therefore, you could listen to the collision events on that collider (or the colliders of the walls).

If you want to use pure Ammo, then you have to start looking into that API as PlayCanvas doesn’t expose those directly. You can see how PlayCanvas handles the Ammo collisions here: https://github.com/playcanvas/engine/blob/d27a44b6d732c0f1bab94ef5126050db16a1d914/src/framework/components/rigid-body/system.js#L485

This is how I would do it:
https://playcanvas.com/editor/project/604666

Script here: https://playcanvas.com/editor/code/604666?tabs=17883481

And that is attached to the barriers here:


#15

I thank you so much! Maybe I understand it ;
I would like to learn how to use Ammo.js


#16

Ammo.js is the C++ Bullet physics library compiled into JS so the documentation for it is hard to find. It involves going through the documentation of Bullet and finding out what is exposed in Ammo.js.

Documentation for Bullet: https://pybullet.org/wordpress/ (closest you are going to get as the C++ site is down).
Exposed functions and variables here: https://github.com/playcanvas/ammo.js/blob/master/ammo.idl

Please note that Ammo.js is not a PlayCanvas library so if you are looking for support, you will have to ask on their GitHub page here https://github.com/kripken/ammo.js/


#17

I just want to learn the API in Ammo.js,for example: this.vehicle.getRigidBody().setAngularFactor(ammoVec);
this.vehicle.getRigidBody().setLinearFactor() …

The reason of bullet is to hard for me …


#18

[quote=“z281159443, post:17, topic:9359, full:true”]
I just want to learn the API in Ammo.js,for example: this.vehicle.getRigidBody().setAngularFactor(ammoVec);
this.vehicle.getRigidBody().setLinearFactor() …

The principle of bullet is to hard for me …


#19

Then you have to learn the Bullet API. There’s no way getting around it. Ammo.js IS Bullet.

Eg. setLinearFactor is listed here in the Bullet documentation. https://pybullet.org/Bullet/BulletFull/classbtRigidBody.html#a00cf3fa28987ffb77764e5bd3605e3ef


#20

thank you very much ,I get it!