fenomas / noa

Experimental voxel game engine.
MIT License
616 stars 91 forks source link

How to get position of an entity? #76

Closed EliteAsian123 closed 5 years ago

EliteAsian123 commented 5 years ago

How do I get the position of let's say, the player?

fenomas commented 5 years ago

Short answer: noa.ents.getPosition(noa.playerEntity)

Long answer: entity data all lives in components, and entity positions live in the position property of the state object of the position component. So the explicit way to get the data would be:

var entID = noa.playerEntity  // 1
var compName = noa.ents.names.position  // "position"
var posdata = noa.ents.getState(entID, compName)
console.log(posdata.position)

However the entities module defines a bunch of accessors for often-used data, here is where they're all defined.

By the way, noa entity positions are always the bottom-center of the entity's AABB.

EliteAsian123 commented 5 years ago

Okay thanks!