2d "zone" detection

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
Paradan
Posts: 16
Joined: Wed May 18, 2011 5:45 pm

2d "zone" detection

Post by Paradan »

hi all,

for my little game demo I'm making I need to detect what kind of terrain the model is over. right now Im just making big invisible models and using the native collision detection. i was wondering if theres an easy way for me to make a B&W zone map and compare the models position to in order to trigger an event.

basically, are they standing in the mud?





Image
User avatar
Kjell
Posts: 1924
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Paradan,

How are you creating / generating your level / terrain? Is it one big texture, or are you using polygons as well?

There are a bunch of different techniques you can use for this .. which one is best depends a little on your situation.

One approach would be to use your terrain as height-map, and determine whether you're "in the mud" based on that. But you might want something with more precision / that's more controllable.

K
Attachments
Yellow = not-in-mud, Red = in-mud. Graphics are just for debugging purposes / to visualize the height-map.
Yellow = not-in-mud, Red = in-mud. Graphics are just for debugging purposes / to visualize the height-map.
Height.png (102.24 KiB) Viewed 7132 times
Paradan
Posts: 16
Joined: Wed May 18, 2011 5:45 pm

Post by Paradan »

im using one giant sprite thats in the OnRender of the ground model.

ive got an ortho cam active and the ground model is 1 unit below everything else. its the only map/level in the demo and player movement will be constrained to its boundaries.
User avatar
Kjell
Posts: 1924
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Paradan,

Alright, the simplest method is probably to "mask" the terrain types using different alpha values. Then on loading the bitmap, you copy the values into a 2D array so they can be read easily by the player(s). Attached is a basic example.

K
Attachments
Terrain.png
Terrain.png (14.01 KiB) Viewed 7107 times
Terrain.zgeproj
(19.46 KiB) Downloaded 491 times
Paradan
Posts: 16
Joined: Wed May 18, 2011 5:45 pm

Post by Paradan »

thank you.

thats exactly what I was looking for.

quick question:

switch(i)
{
case 1: fun;
break;
case 100: excitement;
break;
}

if i = 50 then you get excitement?
User avatar
Kjell
Posts: 1924
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

:)
Paradan wrote:if i = 50 then you get excitement?
No, if "i = 50" then it doesn't do anything. It will only do something when "i" is exactly 1 or 100 in your example.

K
Post Reply