Activating a 3D fountain

Discuss modding questions and implementation details.
User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Activating a 3D fountain

Post by Ralzar »

So I'm looking at adding a drink/thirst effect to Climates & Calories. I would like to make sure that all sources of water you run into in the game are actually possible to use for drinking or refilling your water skin.

However I've run into a problem with the 3D fountains placed in towns.
3Dfountain.PNG
3Dfountain.PNG (324.22 KiB) Viewed 1757 times
When clicking them, I get:

"hit='CombinedModels (UnityEngine.Transform)' static=True"

Now, I know the water is Texture Archive 085, Index 0. But how do I manage to get my mod to see that I am clicking that surface? If there a way to do this?


Doing this did nothing, because I'm hitting this CombinedModels object instead of the texture:

PlayerActivate.RegisterCustomActivation(mod, 85, 0, WaterSourceActivation);

l3lessed
Posts: 1399
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Activating a 3D fountain

Post by l3lessed »

Yes, Easiest way would be a raycast. Have it shoot out a raycast on player clicking the button, then pass the hitobject into the appropriate unity object to grab and check the material texture. You may be able to pull the hitcast object from the weaponmanager object itself. I can't remember off the top of my head it is public accessible or not. If not, you could just recreate a raycast shooter real quick for your script.

Here is the unity reference I would build from.

https://docs.unity3d.com/ScriptReferenc ... xture.html
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
pango
Posts: 3347
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Activating a 3D fountain

Post by pango »

I'm not sure trying to be as specific as making sure you hit a specific texture is a good idea, because that means any model substitution will break your mechanism.
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

imsobadatnicknames
Posts: 371
Joined: Sun Jun 02, 2019 4:28 pm
Location: Colombia

Re: Activating a 3D fountain

Post by imsobadatnicknames »

Is it really necessary to make it so that only activating the water texture refills your waterskin? I don't really think anyone's immersion is gonna be shattered if their waterskin gets refilled by activating any part of the fountain, and being this specific could possibly cause problems with stuff like HandPainted Models or stuff like that if they don't also use the same static texture to represent water.

I have no advice on a technical level, but on a purely game design level this problem seems like you're making things more complicated than necessary for yourself for a benefit that's marginal at best.
Released mods: https://www.nexusmods.com/users/5141135 ... files&BH=0
Daggerfall isn't the only ridiculously intrincate fantasy world simulator with the initials DF that I make mods for: http://www.bay12forums.com/smf/index.php?topic=177071.0

User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Activating a 3D fountain

Post by Ralzar »

Oh no, it doesn’t have to be the water specifically. The problem is that the whole city block is one big combined object. So clicking the fountain seems to be the same as clicking a house wall, for example. The water texture is the only indicator I can see to tell me I’m clicking water.

User avatar
pango
Posts: 3347
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Activating a 3D fountain

Post by pango »

Ah, I understand the problem better now. It's still not a clean solution though.
I found a technical post in the blog explaining how it works for buidlings: https://www.dfworkshop.net/identifying- ... -and-npcs/

I guess that to support what you want, the geometry parser should build bounding boxen for other objects than just buildings? And then some changes in the mod support so it also works with models replacement? Those are my best guesses...
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

l3lessed
Posts: 1399
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Activating a 3D fountain

Post by l3lessed »

Didn't know it treated the fountain as part of the whole block object. I imagine it than reads it all as one mesh render? If so, you could use a raycast.texturecoord to pull specific texture information from the spot the raycast hits, including the pixel color. If you know the different pixel colors used for the water texture, you could have it check for that to detect if water/fountain is hit.

https://forum.unity.com/threads/trying- ... ng.608431/

https://forum.unity.com/threads/trying- ... ng.608431/

This I believe won't work if it renders the fountain as part of the whole block mesh renderer and not as an individual object, but still it is worth looking at.

https://answers.unity.com/questions/171 ... ycast.html
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 1399
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Activating a 3D fountain

Post by l3lessed »

After trying to grab the texture, it won't work because of the terrain object issue you mention.

Maybe this would work to grab the pixel color and check if it is within the water pixel range.

https://answers.unity.com/questions/153 ... dbody.html

The benefit of this is it would work with all water textures it hits, if it works. But, it would screw up if anyone changed the texture.

The bound box option, like is done for houses, would be the best for all objects tied to terrain mesh. This would allow modders to add functionality for more of the world, like the benches near houses or the water troughs and so on.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
Hazelnut
Posts: 3015
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Activating a 3D fountain

Post by Hazelnut »

Well this discussion has got a bit convoluted. :)

This should be fairly simple to achieve using the existing custom activation mod features. Trying to match a hit texture is the wrong approach because this is a model, not a flat. The issue you're having here is that all models of a block are combined in DFU for optimisation. The custom activation code that I added, and was enhanced by BadLuckBurt back in April, should prevent combining of models that have custom actions registered, allowing the standard activation code to operate. However, this was only actually done for RDB layout and will require some small additions to extend this mechanism to RMB and interior layouts. It's quite simple changes and I will submit a PR soon, but this does mean you will have to wait for the next DFU release to come out.

So then the process should be:

1. Disable model combination for RMB layout, run in editor and click on the fountain model to get the model ID. (Set Option_CombineRMB on DaggerfallUnity object to false, or just temporarily modify code in RMBLayout class line 145 to never create a combiner)

2. Register the model for activation using PlayerActivate.RegisterCustomActivation(mod, fountain_model_id, WaterSourceActivation);

3. Profit? ;-)
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Activating a 3D fountain

Post by Ralzar »

Hazelnut wrote: Thu Nov 19, 2020 10:39 am It's quite simple changes and I will submit a PR soon, but this does mean you will have to wait for the next DFU release to come out.
No problem. Since things are generally a bit quiet on the DFU front at the moment I'm taking the time to play some other games for once :D

Post Reply