WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rating: Thread Rating: 19 votes, 5.00 average. Display Modes
  #1  
Old 09-13-2004, 05:24 PM
vduckie vduckie is offline
Member
 
Join Date: Sep 2004
Posts: 1
avatar animations

Hi,

I was using the avatar animations (for example, the sit and the shot) and the avatars always return to their original standing position after completing their animation. For example, if I use viz.act(sit) the avatar will sit down, then pop up back to their original standing position and stay there. If I use viz.state(sit) the avatar will sit down, return to their original position, and continue repeating this. How you you make the avatar sit down and stay there?

So whether I used viz.act or viz.state, I can't seem to get the avatar to do their action (sit or get shot) and then stay where they are (sitting or lying on the ground). How do you get them to stop returning to their original position every time?

Thanks.
Reply With Quote
  #2  
Old 09-14-2004, 09:36 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

Currently, the only way to do this is to use the avatar.speed command. When you set the speed of an avatar to 0, it will effectively freeze it.

I wrote a very short script that shows how to do this. Press the spacebar to activate the animation of the avatar being shot. Once the animation is activated, a timer will be set to expire when the animation is over. The timer will then freeze the avatar.
Code:
import viz
viz.go()

FREEZE_AVATAR = 0

male = viz.add('male.cfg')
male.rotate(180,0,0)
viz.move(0,0,-8)

def onkeydown(key):
	if key == ' ':
		#Perform the action
		male.act(7)
		#Start a timer to freeze the avatar when the action is over
		viz.starttimer(FREEZE_AVATAR,male.getduration(7))
		
viz.callback(viz.KEYDOWN_EVENT,onkeydown)


def ontimer(num):
	if num == FREEZE_AVATAR:
		#Freeze the avatar
		male.speed(0)

viz.callback(viz.TIMER_EVENT,ontimer)
Let me know if you need any more help
Reply With Quote
  #3  
Old 02-15-2006, 04:45 PM
betancourtb82 betancourtb82 is offline
Member
 
Join Date: Jan 2006
Posts: 103
still stuck

I tried running this piece of code and the avatar stood back up. Have you found any other methods of "freezing the avatar"? Also, I'm trying to run the animation of someone getting shot then laying on the ground. I'm not sure if that's different from the sit and shot animation.

Thank you,

Last edited by betancourtb82; 02-15-2006 at 04:56 PM.
Reply With Quote
  #4  
Old 02-15-2006, 05:06 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

Try replacing the starttimer code with the following instead:
Code:
viz.starttimer(FREEZE_AVATAR,male.getduration(7)-0.1)
This will create a buffer zone to ensure the avatar is frozen before the animation fully completes. It should also work with your animation too.
Reply With Quote
  #5  
Old 02-15-2006, 05:51 PM
betancourtb82 betancourtb82 is offline
Member
 
Join Date: Jan 2006
Posts: 103
Yes, I did viz.starttimer(FREEZE_AVATAR,(male.getduration(7)-.06).

By the way, how do you enter code into this forum? I'm sorry I'm asking so many questions, but you have been very helpful. I would like to show you the code I'm working on, but don't know how to format it.

Thanks
Reply With Quote
  #6  
Old 02-15-2006, 05:56 PM
betancourtb82 betancourtb82 is offline
Member
 
Join Date: Jan 2006
Posts: 103
Nevermind that last question, I just figured it out. Now for my real question. The reason I'm writing this code is to create a scenario where someone falls when they get shot (i.e. a projectile hits the avatar, activated by a mouse click). I have modeled my code from the duckcourt demo but can't get the enemy to stay on the ground when shot. I'm thinking it has to do with the way the avatar is "viewed" by the program. I was wondering if you could help me figure out how to distinguish between each element in the array and denote who's getting shot. For now I would be happy just being able to click on the avatars in this code and have them fall and stay down. I think I can go from there. Thanks again


Code:
import viz

viz.go()
avatars = []
FREEZE_AVATAR = 0

#Go through a loop six times.
for i in range(4):
	#Each time you go through the loop, create a new duck and 
	male = viz.add('male.cfg')
	male.translate(-i, 0,10)
	male.rotate(180,0,0)

#Add the new male to the "avatars" array.
	avatars.append(male)


def onkeydown(key):
	if key == 'r':
		print 'R pressed'
		# Kill timer FREEZE_AVATAR
		viz.killtimer(FREEZE_AVATAR)
		male.clear(viz.ALL)
		male.clear(viz.CURRENT_ACTION)
		male.state(1)
		
viz.callback(viz.KEYDOWN_EVENT,onkeydown)



def ontimer(num):
	if num == FREEZE_AVATAR:
		#Freeze the avatar
		male.speed(0)
		

viz.callback(viz.TIMER_EVENT,ontimer)

def onmousedown(button):
	#The mouse button 'button' is being pressed
	if button == viz.MOUSEBUTTON_LEFT:
			#Perform the action
			male.act(7)
			#Start a timer to freeze the avatar when the action is over
			viz.starttimer(FREEZE_AVATAR,(male.getduration(7)-.07),1)
			#male.act(8)	pass

viz.callback(viz.MOUSEDOWN_EVENT,onmousedown)

viz.mouse(viz.OFF)

Last edited by betancourtb82; 02-16-2006 at 11:58 AM.
Reply With Quote
  #7  
Old 02-16-2006, 11:49 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

The code below will create six avatars and allow the user to click on any of them to cause them to fall down and stay down. Let me know if anything is unclear.
Code:
import viz
viz.go()

avatars = []

#Create six avatars
for i in range(6):
	male = viz.add('male.cfg')
	male.translate(i,0,0)
	male.rotate(180,0,0)
	avatars.append(male) #Save avatar in list

def onmousedown(button):
	if button == viz.MOUSEBUTTON_LEFT:
		node = viz.pick() #Get object that was clicked
		if node in avatars: #Check if object is one of the avatars
			node.execute(7) #Execute the "shot" animation
			#Create action to wait for the animation duration then freeeze the avatar
			WaitThenFreeze = vizact.sequence( vizact.waittime(node.getduration(7)-.06), vizact.speed_node(0) )
			node.add(WaitThenFreeze) #Add the action to the avatar
viz.callback(viz.MOUSEDOWN_EVENT,onmousedown)

#Move viewpoint so that all avatars are visible
viz.move(2.5,0,-10)

#Disable mouse navigation
viz.mouse(0)
Reply With Quote
  #8  
Old 02-17-2006, 12:36 PM
betancourtb82 betancourtb82 is offline
Member
 
Join Date: Jan 2006
Posts: 103
Question Collidesphere

I have this bit of code that I am using from the duckcourt example. I can't find anything on the help that deals with collidesphere. Where did that come from and what does it mean.

Thanks

Code:
	#Enable collisions with the ball based on a sphere shape
	ball.collidesphere(0.25)
	ball.isTarget = 0
	collidables.append(ball)
Reply With Quote
  #9  
Old 02-17-2006, 02:04 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

The command tells Vizard to use a sphere with radius 0.25 when checking collisions with the objects using the collidingwith command. The collide functions are currently undocumented. Let me know if you want more information.
Reply With Quote
  #10  
Old 02-24-2006, 01:16 PM
betancourtb82 betancourtb82 is offline
Member
 
Join Date: Jan 2006
Posts: 103
I was wondering if you could help me out. I'm trying to add an animation where, if I click on an avatar, it falls to the ground and disappears. I got the falling part down, but I added the fadeReset sequence to try and delay the disappearing and it doesn't work out. Any ideas?
Code:
def onmousedown(button):
	if button == viz.MOUSEBUTTON_LEFT:
		node = viz.pick() #Get object that was clicked
		if node in avatars: #Check if object is one of the avatars
			node.clear(viz.ALL)
			node.clear(viz.CURRENT_ACTION)
			node.execute(7) #Execute the "shot" animation
			#Create action to wait for the animation duration then freeeze the avatar
			WaitThenFreeze = vizact.sequence( vizact.waittime(node.getduration(7)-.139), vizact.speed_node(0))
			fadeReset = vizact.sequence(vizact.waittime(5),node.remove())
			#vizact.sequence(vizact.waittime(2),avatars.remove(male),1)			
			node.add(WaitThenFreeze) #Add the action to the avatar
			node.add(fadeReset)
Reply With Quote
  #11  
Old 02-24-2006, 02:09 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

The problem is that you are calling node.remove(). This function will immediately delete the object. In this example you need to create an action that will remove the node. Use the following code instead:
Code:
fadeReset = vizact.sequence(vizact.waittime(5),vizact.call(node.remove))
The vizact.call action will simply call the function that you pass to it.
Reply With Quote
  #12  
Old 02-27-2006, 01:00 PM
betancourtb82 betancourtb82 is offline
Member
 
Join Date: Jan 2006
Posts: 103
I think it's working out but I do get some traceback errors. Here is the code:
Code:
def onmousedown(button):
	global i
	if button == viz.MOUSEBUTTON_LEFT:
		node = viz.pick() #Get object that was clicked
		if node in avatars: #Check if object is one of the avatars
			node.clear(viz.ALL)
			node.clear(viz.CURRENT_ACTION)
			node.execute(7) #Execute the "shot" animation
			#Create action to wait for the animation duration then freeeze the avatar
			WaitThenFreeze = vizact.sequence( vizact.waittime(node.getduration(7)-.14), vizact.speed_node(0))
			#vizact.sequence(vizact.waittime(2),avatars.remove(male),1)			
			node.clear(viz.ALL)
			node.clear(viz.CURRENT_ACTION)
			node.add(WaitThenFreeze) #Add the action to the avatar
			node.clear(viz.ALL)
			node.clear(viz.CURRENT_ACTION)
			fadeReset = vizact.sequence(vizact.waittime(1),vizact.call(node.remove))
			node.add(fadeReset)
		i = 2;
Here are the traceback errors. I'm not sure what they all mean.

Code:
Traceback (most recent call last):
  File "C:\Program Files\Vizard25\viz.py", line 5916, in mytimer
    curAction.update(elaps,curAction._obj_)
  File "C:\Program Files\Vizard25\vizact.py", line 653, in update
    self.checkaction(object)
  File "C:\Program Files\Vizard25\vizact.py", line 629, in checkaction
    __endAction__(object,self.curAction)
  File "C:\Program Files\Vizard25\vizact.py", line 219, in __endAction__
    object._action.notifyEndAction(action._obj_,action._actiondata_.callbackData,action._pool_)
AttributeError: 'int' object has no attribute 'notifyEndAction'
Reply With Quote
  #13  
Old 02-27-2006, 01:32 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

Try the following instead:
Code:
node.add(vizact.waittime(1))
node.add(vizact.call(node.remove))
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 10:50 AM.


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