Closed Trenki closed 3 years ago
Hi, the only caveat on collideTerrain is that it assumes the entity already has the physics component (it's the physics engine that actually emits the collision event). Probably noa should emit a log warning if that's not the case I guess.
However for the code you posted, the entity is getting the physics component and the code works as expected for me. To be clear collideTerrain calls a callback
property, and it passes the impulse of the collision and the id of the entity. So the expected usage is like:
ents.addComponent(entityID, ents.names.collideTerrain,{
callback: (impulse, id) => {
console.log('Entity', id, 'terrain collision, impulse:', impulse)
}
})
Anyway for me your code runs as expected, and the callback
function gets called normally (as soon as the spawned entity falls to the ground). What are you seeing?
Sorry, I misunderstood the meaning of the function, which made me think the desired effect was not achieved.The effect I want to know is that Entity hits the terrain while walking forward, how should this state be obtained?
Hi, the callback should get fired when the entity hits terrain while walking, or it does for me. Note that if the entity walks into a one-block barrier, and has the "autoStep" property, then it will step onto the barrier instead of colliding. What behavior are you seeing?
Hi,Andy.I see, my question is how to make the Entity walk without using receivesInputs.
Use noa.ents.setPosition(EId, [1, 2, 3])
for direct position setting.
Alternatively you can modify the state of their movement component (assuming they have one) - source is /src/components/movement.js
noa.ents.getMovement(EId)
Check out the API documentation in /doc/API.md - it's very helpful.
I wanted to check if entities collided with terrain, so I used collideTerrain like CollideEntities, but it didn't work.