PDA

View Full Version : Quick Question


nige777
04-23-2008, 09:45 AM
Calling all Vizards,

I am trying to add the ability to mount and dismount a vehicle (FLT) in my scene. When dismounted the user should be able to walk around the environment as normal. Problem is when I only seem to able to perform this action once, maybe I am trying to do this the wrong way :o. Here is a snippet of code to illustrate the way I am trying to achieve this.

import vizcam

def orbitCamera():
cam = vizcam.PivotNavigate(distance=4)
cam.centerNode(run)
bodyLink.remove()

def normalView():
bodyLink = viz.link(body,view,dstFlag=viz.LINK_BODY)
bodyLink.preTrans([0,-0.29,0.2])

def buttonTimer():
if joy.isButtonDown (3):
vizact.choice([orbitCamera(),normalView()],vizact.LOOP)
vizact.ontimer(viz.FASTEST_EXPIRATION,buttonTimer)

Do I need to use groups? If so, how?

Thanks for any help in advance,

Regards,

Nige

farshizzo
04-23-2008, 05:23 PM
Are you trying to toggle between the orbit camera and normal view when joystick button 3 is pressed? If so, you will need to modify your code to look something like this:import vizcam

cam = vizcam.PivotNavigate(distance=4)
cam.enabled = False

bodyLink = viz.link(body,view,dstFlag=viz.LINK_BODY)
bodyLink.preTrans([0,-0.29,0.2])

def joydown(e):
if e.button == 3:
cam.enabled = not cam.enabled
if cam.enabled:
bodyLink.disable()
cam.centerNode(run)
else:
bodyLink.enable()

viz.callback(vizjoy.BUTTONDOWN_EVENT,joydown)This code should properly toggle between the camera and body link. Let me know if anything is not clear.

nige777
04-24-2008, 08:51 AM
Thanks for the suggestion, it works really well. Unfortunately I posted the question when I was half asleep, so I apologies for the fact that I will now have to ask you a revised question:o. I actually need to be able to dismount the the truck and move around. I control the truck with a joypad with the head ori of the view set to mouselook and envisage controlling the view in the same way when I dismount. Here's the joypad script I'm using to drive the FLT:


#Use joystick to control FLT navigation
def UpdateMovement():

#Get the joystick position
x,y,z = joy.getPosition()

#Get the twist of the joystick
twist = joy.getTwist()

#Using the z value off the twist control for up and down
if abs(y) > 0.3 or abs(y) < -0.3:
SetThrottle(-y)

if abs(y) <0.3 and abs(y) >-0.3:
SetThrottle(0)

if abs(twist) > 0.2 or abs(twist) < -0.2:
steer(twist*70)
steerWheel(-twist*65)

elif abs(twist) < 0.2 or abs(twist) > -0.2:
steer(0)
steerWheel(0)

#UpdateJoystick every frame
vizact.ontimer(viz.FASTEST_EXPIRATION,UpdateMoveme nt)

So what I think I am asking is how do I mount and dismount from the truck while using the same controls to manipulate the main view.

Thanks for your patience,:o

Nige

farshizzo
04-28-2008, 12:33 PM
I'm not exactly clear on what you are trying to accomplish. It seems like you just need to disable the UpdateMovement function while you are dismounted from the truck, and enable it when you are mounted. Let me know if I misunderstood your question.

nige777
05-07-2008, 02:39 PM
Hi fashizzo,

Yes, you are quite right, I need to disable the UpdateFLTMovement() function whilst dismounted from the truck. :o However, I now have 2 functions, one for moving the truck, one for moving the view, but am unable (in my sleep deprived state :eek:) to switch toggle between them. I have tried all manner of enable and disable combinations - but to no avail. I feel that (once again) I am missing something really simple :rolleyes:

All help gratefully received :D

nige777
05-08-2008, 05:50 AM
Please disregard the last post :o - I have had some sleep and my brain has started working again :)

I just put the two functions in a timer and just call or kill whichever one I want! :rolleyes:


Cheers

Nige