diff --git a/jme3-bullet/src/common/java/com/jme3/bullet/control/CharacterControl.java b/jme3-bullet/src/common/java/com/jme3/bullet/control/CharacterControl.java index 85dcf1a95..e34b5b3b6 100644 --- a/jme3-bullet/src/common/java/com/jme3/bullet/control/CharacterControl.java +++ b/jme3-bullet/src/common/java/com/jme3/bullet/control/CharacterControl.java @@ -102,6 +102,7 @@ public class CharacterControl extends PhysicsCharacter implements PhysicsControl control.setCcdSweptSphereRadius(getCcdSweptSphereRadius()); control.setCollideWithGroups(getCollideWithGroups()); control.setCollisionGroup(getCollisionGroup()); + control.setContactResponse(isContactResponse()); control.setFallSpeed(getFallSpeed()); control.setGravity(getGravity()); control.setJumpSpeed(getJumpSpeed()); diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsCharacter.java b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsCharacter.java index 148199b75..756c0a8d9 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsCharacter.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsCharacter.java @@ -31,6 +31,7 @@ */ package com.jme3.bullet.objects; +import com.jme3.bullet.collision.CollisionFlag; import com.jme3.bullet.collision.PhysicsCollisionObject; import com.jme3.bullet.collision.shapes.CollisionShape; import com.jme3.export.InputCapsule; @@ -50,7 +51,6 @@ import java.util.logging.Logger; * @author normenhansen */ public class PhysicsCharacter extends PhysicsCollisionObject { - /** * Unique identifier of btKinematicCharacterController (as opposed to its * collision object, which is a ghost). Constructors are responsible for @@ -456,6 +456,22 @@ public class PhysicsCharacter extends PhysicsCollisionObject { private native float getMaxSlope(long characterId); + /** + * Enable/disable this character's contact response. + * + * @param responsive true to respond to contacts, false to ignore them + * (default=true) + */ + public void setContactResponse(boolean responsive) { + int flags = getCollisionFlags(objectId); + if (responsive) { + flags &= ~CollisionFlag.NO_CONTACT_RESPONSE; + } else { + flags |= CollisionFlag.NO_CONTACT_RESPONSE; + } + setCollisionFlags(objectId, flags); + } + /** * Test whether this character is on the ground. * diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java index 513187658..80285f62a 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java @@ -57,12 +57,6 @@ import java.util.logging.Logger; * @author normenhansen */ public class PhysicsRigidBody extends PhysicsCollisionObject { - - /** - * copy of the contact response state: true→responds to contacts, - * false→doesn't respond (default=true) - */ - private boolean contactResponseState = true; /** * motion state */ @@ -390,8 +384,6 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { flags |= CollisionFlag.NO_CONTACT_RESPONSE; } setCollisionFlags(objectId, flags); - - contactResponseState = responsive; } /** diff --git a/jme3-jbullet/src/main/java/com/jme3/bullet/objects/PhysicsCharacter.java b/jme3-jbullet/src/main/java/com/jme3/bullet/objects/PhysicsCharacter.java index c057d99d2..1d7f54038 100644 --- a/jme3-jbullet/src/main/java/com/jme3/bullet/objects/PhysicsCharacter.java +++ b/jme3-jbullet/src/main/java/com/jme3/bullet/objects/PhysicsCharacter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2012 jMonkeyEngine + * Copyright (c) 2009-2018 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -169,6 +169,26 @@ public class PhysicsCharacter extends PhysicsCollisionObject { return character.getMaxSlope(); } + /** + * Enable/disable this body's contact response. + * + * @param newState true to respond to contacts (default=true) + */ + public void setContactResponse(boolean newState) { + if (!newState) { + throw new UnsupportedOperationException("Not implemented."); + } + } + + /** + * Test whether this body responds to contacts. + * + * @return true if responsive, otherwise false + */ + public boolean isContactResponse() { + return true; + } + public boolean onGround() { return character.onGround(); } @@ -279,6 +299,7 @@ public class PhysicsCharacter extends PhysicsCollisionObject { buildObject(); character = new KinematicCharacterController(gObject, (ConvexShape) collisionShape.getCShape(), stepHeight); setGravity(capsule.readFloat("gravity", 9.8f * 3)); + setContactResponse(capsule.readBoolean("contactResponse", true)); setMaxSlope(capsule.readFloat("maxSlope", 1.0f)); setFallSpeed(capsule.readFloat("fallSpeed", 55.0f)); setJumpSpeed(capsule.readFloat("jumpSpeed", 10.0f));