Collidable camera

Hey there,
My 3D space game project has been going pretty well :smiley:
I’ve got a collision detector going on, and the TransformGroups in the game are bashing together quite happily. As the user is flying the ViewingPlatform, I need to stop them smashing into enemy ships with gleeful abandon. Unfortunately, the collision class doesn’t seem to affect the ViewingPlatform, and I can’t fathom it ???

            /**
                  A straight simple universe isn't enough for our needs,
                  because we can't mess with the ViewingPlatform once
                  it's been made, so we need to make our own stuff
            */
            ViewingPlatform thePlatform = new ViewingPlatform();
            
            // Make the view platform collidable
        BoundingSphere viewBounds = new BoundingSphere();
        viewBounds.setRadius(20.0);
            thePlatform.setCapability(ViewingPlatform.ALLOW_COLLIDABLE_WRITE);
            thePlatform.setCollisionBounds(viewBounds);
            thePlatform.setCollidable(true);
            thePlatform.setCapability(ViewPlatform.ALLOW_BOUNDS_WRITE);
            thePlatform.setBounds(viewBounds);
            Collider viewWatcher = new Collider(thePlatform, viewBounds, this);
            thePlatform.setUserData("the player");
            
            Viewer theViewer = new Viewer(canvas);
            
            universe = new SimpleUniverse(thePlatform, theViewer);
        
        scene.addChild(viewWatcher);

I don’t think the Collision class code will help, but I’ll appened the post with it anyway.

Thanks guys, I know it’s just a silly mistake I’m making :frowning:
Chris


public class Collider extends Behavior
{
    private Node theNode;
    private Engine theEngine;
    private WakeupCriterion[] cases;
    private WakeupOr allCases;
    
    public Collider(Node inputNode, Bounds inputBounds, Engine inputEngine)
    {
        theNode = inputNode;
        theEngine = inputEngine;
        setSchedulingBounds(inputBounds);
    }
    
    
    public void initialize()
    {
        cases = new WakeupCriterion[3];
        cases[0] = new WakeupOnCollisionEntry(theNode);
        cases[1] = new WakeupOnCollisionExit(theNode);
        cases[2] = new WakeupOnCollisionMovement(theNode);
        allCases = new WakeupOr(cases);
        wakeupOn(allCases);
    }
    
    /**
     * Where the work is done in this class.  A message is printed out
     * using the userData of the object collided with.  The wake up
     * condition is then set to the OR'ed criterion again.
     */
    public void processStimulus(Enumeration criteria) 
    {
        WakeupCriterion theCriterion = null;
        
        try
        {
            theCriterion = (WakeupCriterion)criteria.nextElement();
        }
        catch (NoSuchElementException e)
        {
        }
    
        if (theCriterion != null)
        {
            if (theCriterion instanceof WakeupOnCollisionEntry) 
            {
                Node theLeaf = ((WakeupOnCollisionEntry) theCriterion).getTriggeringPath().getObject();
                System.out.println("Collided with " + theLeaf.getUserData());
            }
            else if (theCriterion instanceof WakeupOnCollisionExit) 
            {
                Node theLeaf = ((WakeupOnCollisionExit) theCriterion).getTriggeringPath().getObject();
                System.out.println("Stopped colliding with " + theLeaf.getUserData());
            } 
            else 
            {
                Node theLeaf = ((WakeupOnCollisionMovement) theCriterion).getTriggeringPath().getObject();
                System.out.println("Moved whilst colliding with " + theLeaf.getUserData());
            }
        }
        
        wakeupOn(allCases);
    }
}

In www.j3d.org you will find some collision code already made for you. I think the trick is to create your own collison geometry and attach it to the vieweing platform not using the platform itself as a collision object.

Thanks for the hint, Zingbat, but I’m still at square one. I think I’ve tried everything, attaching groups below the various viewers, setting platform geometry, using the setViewPlatformBehavior method (by extending ViewPlatformBehavior), manually pulling out the view platform transform group and attaching the collision detector to that… And still nothing :-[

From what I can tell, the way the J3D guys do it is by actually having a separate transform group to the view platform, and sending movement commands to that. Then a method is called every frame updating the view platform’s position to that of the separate transform group.

Can anyone confirm that that is the quickest/only way to do this? Or, for that matter, I’m interpreting it correctly? I don’t want to start coding all that stuff and find out that it’s yet another avenue that I can’t get to work. Surely there must be a better way than that. I’m loathe to use their code as this is an assessed university project, but if there’s no other way there’s no other way :frowning:

Any help would be seriously appreciated. I just broke my hand after punching the wall in frustration!

Ouch.

Chris