Hey there,
My 3D space game project has been going pretty well
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
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);
}
}