WorldViz User Forum

WorldViz User Forum (
-   Vizard (
-   -   Spawn Avatar in front of User (

Seadna 02-25-2016 04:39 AM

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.


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.setPosition(a + 5,b,c, viz.REL_LOCAL)
                ColShape = Cloud.collideMesh()
vizact.onbuttondown(button_addbot, AddBot)

Jeff 02-25-2016 06:08 AM

Here's an example, navigate around and you'll see a pigeon appear in front of the view every two seconds:


import viz
import vizact


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

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])

Seadna 02-25-2016 07:16 AM

Thank you,

This worked like a charm.

JasmineJasmine 02-29-2016 04:16 PM

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.

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

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