WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-25-2016, 04:39 AM
Seadna Seadna is offline
Member
 
Join Date: Nov 2015
Posts: 40
Question Spawn Avatar in front of User

Hi folks,

I have been trying to spawn an avatar model a few feet in front of the main view. I can get it to spawn at the location of the main view but not in front. I can offset the spawn location but not in relation to the viewpoint. Any help would be much appreciated.

Code:
def AddBot():
                x,y,z,d = viz.MainView.getAxisAngle()
                a,b,c = viz.MainView.getPosition()
                modelfile = randint(1,3)
                dudestate = randint(1, 14)
                if modelfile == 1:
                                dude = viz.add('vcc_male.cfg') 
                elif modelfile == 2:
                                dude = viz.add('vcc_male2.cfg') 
                elif modelfile == 3:
                                dude = viz.add('vcc_female.cfg') 
                dude.state(dudestate) 
                dude.setPosition(a + 5,b,c, viz.REL_LOCAL)
                dude.setAxisAngle(0,y,0,d)
                ColShape = Cloud.collideMesh()
                dude.collideCapsule()
vizact.onbuttondown(button_addbot, AddBot)
Reply With Quote
  #2  
Old 02-25-2016, 06:08 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Here's an example, navigate around and you'll see a pigeon appear in front of the view every two seconds:

Code:
import viz
import vizact
viz.go()

viz.addChild('piazza.osgb')

avatar = viz.addAvatar('pigeon.cfg',pos=[0,0,6],euler=[180,0,0],scale=[4,4,4])
avatar.state(1)

def spawnAvatar():
	
	pos = viz.MainView.getPosition()
	yaw = viz.MainView.getEuler()[0]
	vector = viz.MainView.getMatrix().getForward()
	amount = 5
	x,y,z = vizmat.MoveAlongVector(pos,vector,amount)
	a = avatar.clone(pos=[x,0,z],euler=[yaw-180,0,0],scale=[4,4,4])
	
vizact.ontimer(2,spawnAvatar)

Last edited by Jeff; 02-25-2016 at 06:18 AM.
Reply With Quote
  #3  
Old 02-25-2016, 07:16 AM
Seadna Seadna is offline
Member
 
Join Date: Nov 2015
Posts: 40
Thank you,

This worked like a charm.
Reply With Quote
  #4  
Old 02-29-2016, 04:16 PM
JasmineJasmine JasmineJasmine is offline
Member
 
Join Date: Feb 2016
Posts: 6
You can use the player.transform.forward direction to get the players direction as a vector and transform.rotation to get the orientation. You can also do math operations of vectors which makes things so much better than modifying the components.
Reply With Quote
Reply

Tags
avatar, position, relative, viewpoint

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unexpected Avatar lookAt() behavior when using yield statements chris2307 Vizard 2 12-17-2013 03:58 AM
Avatar eye contact with user as it moves Ducky Vizard 1 03-01-2013 01:23 PM
How to make avatar always in front of youself (e.g. 20cm) when direction changes Xianshi Xie Vizard 2 06-30-2009 12:13 PM
Has user perception of avatar expressions been tested? Karla Vizard 3 10-28-2008 11:32 AM


All times are GMT -7. The time now is 05:42 AM.


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