fenomas / noa

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

Jumping out of water #45

Closed terrac closed 5 years ago

terrac commented 6 years ago

I've noticed that water is treated like air in terms of how many jumps you get. So you can't repeatedly jump out of it unless you have a bunch of air jumps. Should it be treated more like ground?

fenomas commented 6 years ago

Hi, sorry for the super-late reply. The easiest way to tweak stuff like this would be to override the movement component. Not by forking noa and editing it I mean, but at runtime by removing the default component and replacing it with your own. To do this safely just make sure you add the new component to any entities that had the old one - I do this thusly:

function overwriteComponent(noa, compName, compDef) {
    // list of ids having the old component
    var ids = noa.ents.getStatesList(compName).map(function (s) { return s.__id })
    // nuke old component
    noa.ents.deleteComponent(compName)
    // add new one
    noa.ents.names[compName] = noa.ents.createComponent(compDef)
    // add component to ids that had the previous one (with default state)
    ids.forEach(function (id) {
        noa.ents.addComponent(id, compName)
    })
}

Hope that's fairly clear. In your case, compDef would just be a copy of the default movement component, except with the system function changed with whatever jump rules you prefer.

Let me know if this works for you!

fenomas commented 5 years ago

Closing this on the assumption that it worked ;)