Topic: Simulate a Tag system

Hello guys i was able to fake a mouse over script here, i change the cursor image by a hand image when i mouse over a object, i use the rayhit function to detect the object and i just activate or deactivate a fake cursor (a plane with a image with emission on and a follow plus lookAt behavior, that is right in front of the camera) when the ray detects the object i want the cursor changes, works fantastically.

But now i have a question, from my inexperienced point of view, every time i want to make a object "mouse over" enabled, i need to make individual functions to all new objects (with repeated code), imo if true this would be unmanageable with so many different interactive objects on a scene, (and the script would be very confusing and big), but if i add a way to Tag a object then this would not be a major problem, does it?  Because i think only one function would work for all objects with different names but tagged for example "interactive".

for example a getTag() function would be nice but has it doesn't exist, at least i don't see it anywhere, what can you guys suggest that i do? Do i really need to make a bunch of functions for every object on my level that i want interactive or there's a more easy way?

Last edited by Argoon (2013-08-27 01:21:19)

Re: Simulate a Tag system

Argoon wrote:

Hello guys i was able to fake a mouse over script here, i change the cursor image by a hand image when i mouse over a object, i use the rayhit function to detect the object and i just activate or deactivate a fake cursor (a plane with a image with emission on and a follow plus lookAt behavior, that is right in front of the camera) when the ray detects the object i want the cursor changes, works fantastically.

But now i have a question, from my inexperienced point of view, every time i want to make a object "mouse over" enabled, i need to make individual functions to all new objects (with repeated code), imo if true this would be unmanageable with so many different interactive objects on a scene, (and the script would be very confusing and big), but if i add a way to Tag a object then this would not be a major problem, does it?  Because i think only one function would work for all objects with different names but tagged for example "interactive".

for example a getTag() function would be nice but has it doesn't exist, at least i don't see it anywhere, what can you guys suggest that i do? Do i really need to make a bunch of functions for every object on my level that i want interactive or there's a more easy way?

What you really want is a CLASS. This is part of the reason I made my post on how to make classes in lua. Anael also responded with a link to the wiki.

Also, have you seen the:

getProjectedPoint(object, point)

function?

I think that has something to do with the mouse also.

On Classes:

Classes are just what they sound like. An apple belongs to the class of FRUIT, and so does an orange. A man belongs to the class of HUMANS, and so does a woman.

Fruit also have various properties, like TASTE and COLOR and TYPE. These would be variables in the class. And humans have various properties also, like a NAME and an AGE and a RACE. Humans also have ABILITIES. Humans can WALK, and TALK, and JUMP, etc. These would be functions in the class (Also called METHODS).

So if I were to create a new variable named manzana, and I made it part of the fruit class, I could just give it properties and abilities without having to type out the function over and over for a new fruit.

When you make variables that have these abilities and properties they are called OBJECTS.

Example:

--We make joe a person
joe = newPerson()

--now we can do stuff with joe
joe:Walk()
joe:Speak()
joe:Dance()

print (joe.name)
print (joe.age)
print (joe.height)

--create another person
sara= newPerson()
sara:Speak()
sara:Dance()
sara:Walk()

print (sara.height)
print (sara.age)
print (sara.name)

And we could keep doing this over and over and over.

Last edited by Tutorial Doctor (2013-08-27 01:40:33)

Re: Simulate a Tag system

Thanks Tutorial Doctor i will read more about the classes then, i do know some of that terms because of my time trying to learn C# big_smile.

About getProjectedPoint(object, point) i did saw it has also getUnProjectedPoint(object, point) but there's no real tutorial on the forum (if you can call it that) that shows how to use the first, and when i used the later i just couldn't make it work well, rayhit function was what i tried next and it worked right away, has i said i'm not a real coder, for the most part i need to see already made code to be able to implement my ideas, i just lack for the time being a "coder brain" where i see my ideas on my head already "code" formated, big_smile ,  i'm more of a artist.  Even the idea that made it possible for me to make the "mouse over" code was a Anael thread showing another user how to use the rayhit funtion with screenshots.

But day after day i'm starting to "get it".

Again i will read more about the classes then, good night.

Last edited by Argoon (2013-08-27 02:51:05)

Re: Simulate a Tag system

take care. smile

Re: Simulate a Tag system

Argoon wrote:

About getProjectedPoint(object, point) i did saw it has also getUnProjectedPoint(object, point) but there's no real tutorial on the forum (if you can call it that) that shows how to use the first

I did this http://wiki.maratis3d.org/index.php?tit … ng_GUIDemo but it's C++ not Lua. It uses that function.
BTW the function itself it's very simple, you have a point in your scene, let's say where your game character is, let's say it's P(50,50,0). You do

MVector3 position = camera->getProjectedPoint(MVector3(50,50,0));

and what you get is the screen 2D coordinates stored in the variable "position". Z is of course not counted.
As simple as that.
If then you want to display something (a text for example) at such position, it's a bit trickier since Maratis don't have a 2D GUI "engine" yet, but you can use my tutorial linked above to see how to do it with the current version.

Last edited by 255 (2013-08-27 10:18:47)

Re: Simulate a Tag system

Thanks 255 smile i will experiment with it, btw showing text is not a problem on maratis even without a 2D "engine" you just use a text object and use activate() and deactivate() to hide or show it at the location you want.

Re: Simulate a Tag system

Yes but it's in 3d, if you want it to stay 2D in relation to the player point of view, and always at the same size, etc, you have to use the GUI Demo plus my tutorial.

Re: Simulate a Tag system

about gui >
there is also a script method to draw another scene on top of a camera (like GUI Demo) : http://wiki.maratis3d.org/index.php?tit … ameraLayer

Re: Simulate a Tag system

Thanks anael that will be useful when i try my read book UI system.