Lua: check for object above water

Status
Not open for further replies.

OtherChen

The other one
I'm trying to make something hover close to the ground/water without touching it. Ground is easy: (thing.z - thing.floorz). For water, (thing.z - thing.watertop) doesn't work unless the object is underwater, so I'm spawning a "sinker" dummy mobj on the floor under the object and checking its properties. I've tried the following methods:
  • Reading the sinker's eflags doesn't work, as (sinker.eflags & MFE_UNDERWATER) always returns false.
  • Reading the sinker's watertop always gives INT32_MAX, so (sinker.watertop > sinker.z) always returns true.
  • Using different mobj types for the dummy: thok trails, water splishes, fire, rings, red rings, and crawlas. I left the sprites showing and the objects are clearly underwater.
  • Changing the dummy's scale and height to various values, including FRACUNIT, 1, and 0.
  • Waiting a few tics and checking the underwater-ness of dummy mobjs from a few tics ago gives the same result

This shouldn't be so difficult. What am I missing? Is there a parallel to mobj.watertop that checks for water below an object rather than the surface above the object?
 
Does the sinker have MF_NOTHINK? If so, that's your problem. Internal mechanisms such as mo.eflags and mo.watertop are only set if there's a thinker running to do stuff. You might be able to get away with MF_SCENERY (which is a reduced, less intensive thinker) if all you want is mo.eflags, but I'm not sure where mo.watertop is handled.
 
I tried using objects that I knew had thinkers, like rings and crawlas. Still no luck (unless filling GFZ1 with rings and crawlas has some artistic merit behind it).
 
Rings have just MF_SCENERY iirc, and don't update anything after spawn. Crawlas definitely have thinkers, though, which confuses me. Have you tried defining your own freeslot MT_SINKER object?

Can't help that much because I'm spending today travelling, but.
 
Does the "sinker" object have any health at all? IIRC objects with no health don't check for water (and thus don't set any properties to do with water).
 
Solved it; the sinker mobj needs to persist for a few tics while checking its flags. Or something.

Code:
local function GetHoverZ(thing)
	-- Get the floor or water height under a hovering object
	-- (lags behind by 1 tic)
	local HOVERZ = thing.floorz
	if thing.sinkerhelper and thing.sinkerhelper.valid then
		if thing.sinkerhelper.eflags & MFE_UNDERWATER then
			HOVERZ = thing.sinkerhelper.watertop
		end
	end
	thing.sinkerhelper = P_SpawnMobj(thing.x, thing.y, thing.floorz, MT_MOUSE)
	if thing.sinkerhelper and thing.sinkerhelper.valid then -- Can't be too careful
		thing.sinkerhelper.fuse = 3
		thing.sinkerhelper.flags2 = MF2_DONTDRAW -- remove if thing is MT_MOUSEHOLE
	end
	return HOVERZ
end
 
Status
Not open for further replies.

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top