Frotty / Frentity

Hierarchical Entity Framework
Apache License 2.0
11 stars 6 forks source link

Physics module #17

Open StN-NL opened 3 weeks ago

StN-NL commented 3 weeks ago

Hello, using the physics module with cliffs only works fine (a bit ugly though), but when using height instead of cliffs (terrain tool), units start to float (cliff level 0) or objects fall below the surface (higher cliff levels). This is expected?

Frotty commented 3 weeks ago

No, that is not expected. The system works on terrain height, there is no difference between cliffs and terrain tool height. Also, not sure what you mean by "ugly". Post a reproducible example.

StN-NL commented 3 weeks ago

When I say ugly I am just referencing the terraining crowd (point A): https://www.hiveworkshop.com/threads/advanced-terraining-tutorial.203428/

This is the map: https://github.com/StN-NL/sheepz

The default map is a tropical island (the one in the top left):

  1. Running the default setup you will see the sheep is floating, especially near the beach (global cliff level 0)
  2. If you then in the World Editor > Advanced > Adjust Cliff Levels > +2
  3. The sheep is no longer floating but missiles are going underground (press F to get access to missiles)

Alternatively, using only cliffs, where everything works just fine:

  1. comment lines 747-749 from GameMenu.wurst
  2. uncomment lines 750-750 from GameMenu.wurst
  3. this will change the playable coordinates to a different "map" (the purple one in the center) which uses cliffs only

Hope this makes any sense, let me know if you need more info.

Frotty commented 3 weeks ago

It's not really feasible for me to check an entire map's unknown to me script for this specific error, there could be many side effects coming from all kinds of places. I created a minimal example which I think is similar to what you're looking for, a unit that falls down, stays on the ground, but can jump. It seems to work fine for me on a map with smooth hills with negative and positive z values:

package Usage
import EntityManagement
import Projectile
import Heightmap
import PhysicsEntity
import ClosureKeyPresses

class TestUnitEntity extends UnitEntity
    use PhysicsModule

    construct(vec3 pos)
        super(createUnitZ(players[0], 'hfoo', pos, angle(0)), pos)
        print(GetObjectName(0))
        sleeps = false

        onKeyPress(OSKEY_B) ->
            addVel(actor.getFacingAngle().toVec(10).withZ(25))

    override function update()
        super.update()
        physicsUpdate(this)
        print(pos.toString())

init
    new TestUnitEntity(ZERO2.withHeightMap(256))

    startEntityLoop()

Only thing from a short look over your code I saw is that you call physicUpdate before update, it should be after. But that's not the cause of the problem. Since this works, I am quite certain the problem is in your code.

So, please create a similar small example to reproduce the issue if you want me to analyze it further.

stijn-nefkens commented 3 weeks ago

If you were to run your code using my map Sheepz.w3x you will find your footman is floating near the shores.

Only modification needed to land it on the island:

new TestUnitEntity(vec2(-8000, 8000).withHeightMap(256))

This might be an issue with the map itself then, and I might try to remake it.

Maybe a by-effect of resizing the map.

EDIT: it is definitively an issue with the map file. Sorry for bothering you with this. I created a new map and it seems to work fine.

Frotty commented 2 weeks ago

No problem. Perhaps it's an issue if you change cliff level with water or something, making the height values not be correct. Can this issue be closed then?

StN-NL commented 2 weeks ago

Unfortunately recreating the map first caused me to think it worked as I placed the island in a different position.

But when I moved it back to the topleft the same issue reappeared.

To pinpoint the issue I created maps of several sizes with cliff level 4 just to have initial height.

Then I started clicking around to see visualize the heightmap using:

package Test
import ClosureEvents
import FText
import Heightmap

function getMousePos3() returns vec3
    let x = EventData.getPlayerMouseX()
    let y = EventData.getPlayerMouseY()
    let z = vec2(x, y).getHeightMap()
    return vec3(x, y, z)

init
    FogMaskEnableOff()
    FogEnableOff()

    EventListener.add(EVENT_PLAYER_MOUSE_DOWN) ->
        let pos = getMousePos3()
        flashEffect("Abilities\\Spells\\NightElf\\TrueshotAura\\TrueshotAura.mdx", pos)
        createFText(pos.toVec2().toVec3(), pos.toString(), 10, 10, ZERO2)

Turns out that the larger the map the smaller the heightmap coverage. The surface that is not covered is for the higher Y values. It seems that the maximum area covered by the heightmap is 268,435,456 or 16,384 tiles (128x128).

To reproduce: 1) create a new map where:

Frotty commented 2 weeks ago

Ok, I see, so it's due to max array size in Jass. Lua wouldn't have this problem, but it has many others 😄 . With the 32768 max size the heightmap can only cover 181x181 tiles, and it starts in bottom right corner, so in the top part of the map the index exceeds 32768. I guess I never made such a big map that the issue would come up. Also, the heightmap is a somewhat recent addition in order to prevent desyncs due to terrain deformations and such. I kept it to a single array for performance’s sake, but I guess if you want to support larger sizes it would require some splitting up or reverting to using regular terrainZ instead, could add an option for that.

StN-NL commented 2 weeks ago

Ok, I will reduce the map size for full coverage, sounds like the best approach here. Feel free to close. Before I forget, thanks for Wurst ;)

Frotty commented 2 weeks ago

Well not the best but the fastest workaround I guess. I can add something if I get the time. Enjoy your Wurst.