WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Actions while clicking an avatar (https://forum.worldviz.com/showthread.php?t=1688)

TrashcanPatrol 10-23-2008 02:16 PM

Actions while clicking an avatar
 
Hello, is it possible to have an action occur when you click on a specific place on an avatar? If so, how can this be done?
What I'm trying to do is have a drop-down menu where a "toolbox" is. If the player selects the correct tool, which is medicine in this case, MEDICINE will be set to True. Then, the cursor will change to an image of a pill or something, and if the player clicks on the patient's face and MEDICINE = True, the patient will respond and say "I feel better" or something to that extent.
How could I do this? I have a dropdown already that prints "Medicine equipped" when the medicine is selected, as well as turns MEDICINE to True...

Jeff 10-23-2008 03:35 PM

You can use viz.pick() to find what object the mouse is pointing at. Here's some code that uses viz.pick and checks to see if the mouse is pointing at the avatar's head mesh, body mesh, or some other object. Depending on what is picked the avatar will change animations.

Code:

import viz

viz.go()

viz.add('court.ive')
avatar = viz.add('vcc_male.cfg', pos = [0,0,5], euler = [180,0,0])
avatar.state(1)


def onMouseDown(button):
       
        #if you pass in a value 1 a VizIntersect object will be returned
        object = viz.pick(1)
       
        if object.valid and object.name == 'casual32_m_highpoly.CMFX':
                print "you picked the avatar's head"
                avatar.state(2)
        elif object.valid and object.name == 'casual32_m_highpoly01.CMFX':
                avatar.state(4)
                print "you picked the avatar's body"
        else:
                avatar.state(1)
                print "you picked " + object.name
       
               

viz.callback(viz.MOUSEDOWN_EVENT,onMouseDown)


TrashcanPatrol 11-18-2008 01:23 PM

That code works great! But I am having some trouble trying to assign it to a value... sorry if I'm not very descriptive, I have it all planned out in my head and the thoughts aren't very precise when typing them out.

There's a value that is turned to 'ON' when the player selects an option from a dropdown menu... my trouble is I want the player to only be able to select an avatar and/or different parts of the avatar only when the player has selected this option, so only when the value is 'ON' the player will be able to click on the avatar. If that makes any sense >_<
What happens when I try this in my code is, instead of having the console print "You clicked the avatar's head", it says "You clicked casual32_m_highfoly.CMFX" [The code is supposed to make it say the head if you clicked the head, and whatever you clicked besides that would just be casual32_m_highfoly.CMFX or whatever the filename is for it]
How can I make it work so that you can pick a part only if a variable is enabled?

Jeff 11-19-2008 11:04 AM

is this what you mean. You can only click on the avatar when the dropdown is set to ON.

Code:

import viz

viz.go()

viz.add('court.ive')
avatar = viz.add('vcc_male.cfg', pos = [0,0,5], euler = [180,0,0])
avatar.state(1)


click_avatar = True

list = viz.addDropList()
list.addItems(['ON','OFF'])
list.translate(.85,.95)


def dropListChanged(e):

        global click_avatar

        if e.newSel == 0:
                click_avatar = True
        else:
                click_avatar = False
       
       
vizact.onlist( list, dropListChanged )


def onMouseDown(button):
       
        #if you pass in a value 1 a VizIntersect object will be returned
        object = viz.pick(1)
       
        if object.valid and click_avatar == True:
       
                if object.name == 'casual32_m_highpoly.CMFX':
                        print "you picked the avatar's head"
                        avatar.state(2)
       
                elif object.name == 'casual32_m_highpoly01.CMFX':
                        avatar.state(4)
                        print "you picked the avatar's body"
                else:
                        avatar.state(1)
                        print "you picked " + object.name
       
               

viz.callback(viz.MOUSEDOWN_EVENT,onMouseDown)


TrashcanPatrol 12-02-2008 01:56 PM

That is what I've been looking for! Thanks Jeff!


All times are GMT -7. The time now is 01:01 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC