Skip to content

Commit d8acd30

Browse files
authored
implement setContactResponse(boolean) for PhysicsCharacter (issue #964) (#971)
1 parent cde3c39 commit d8acd30

4 files changed

Lines changed: 40 additions & 10 deletions

File tree

jme3-bullet/src/common/java/com/jme3/bullet/control/CharacterControl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public Object jmeClone() {
102102
control.setCcdSweptSphereRadius(getCcdSweptSphereRadius());
103103
control.setCollideWithGroups(getCollideWithGroups());
104104
control.setCollisionGroup(getCollisionGroup());
105+
control.setContactResponse(isContactResponse());
105106
control.setFallSpeed(getFallSpeed());
106107
control.setGravity(getGravity());
107108
control.setJumpSpeed(getJumpSpeed());

jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsCharacter.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
*/
3232
package com.jme3.bullet.objects;
3333

34+
import com.jme3.bullet.collision.CollisionFlag;
3435
import com.jme3.bullet.collision.PhysicsCollisionObject;
3536
import com.jme3.bullet.collision.shapes.CollisionShape;
3637
import com.jme3.export.InputCapsule;
@@ -50,7 +51,6 @@
5051
* @author normenhansen
5152
*/
5253
public class PhysicsCharacter extends PhysicsCollisionObject {
53-
5454
/**
5555
* Unique identifier of btKinematicCharacterController (as opposed to its
5656
* collision object, which is a ghost). Constructors are responsible for
@@ -456,6 +456,22 @@ public float getMaxSlope() {
456456

457457
private native float getMaxSlope(long characterId);
458458

459+
/**
460+
* Enable/disable this character's contact response.
461+
*
462+
* @param responsive true to respond to contacts, false to ignore them
463+
* (default=true)
464+
*/
465+
public void setContactResponse(boolean responsive) {
466+
int flags = getCollisionFlags(objectId);
467+
if (responsive) {
468+
flags &= ~CollisionFlag.NO_CONTACT_RESPONSE;
469+
} else {
470+
flags |= CollisionFlag.NO_CONTACT_RESPONSE;
471+
}
472+
setCollisionFlags(objectId, flags);
473+
}
474+
459475
/**
460476
* Test whether this character is on the ground.
461477
*

jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@
5757
* @author normenhansen
5858
*/
5959
public class PhysicsRigidBody extends PhysicsCollisionObject {
60-
61-
/**
62-
* copy of the contact response state: true→responds to contacts,
63-
* false→doesn't respond (default=true)
64-
*/
65-
private boolean contactResponseState = true;
6660
/**
6761
* motion state
6862
*/
@@ -390,8 +384,6 @@ public void setContactResponse(boolean responsive) {
390384
flags |= CollisionFlag.NO_CONTACT_RESPONSE;
391385
}
392386
setCollisionFlags(objectId, flags);
393-
394-
contactResponseState = responsive;
395387
}
396388

397389
/**

jme3-jbullet/src/main/java/com/jme3/bullet/objects/PhysicsCharacter.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2012 jMonkeyEngine
2+
* Copyright (c) 2009-2018 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -169,6 +169,26 @@ public float getMaxSlope() {
169169
return character.getMaxSlope();
170170
}
171171

172+
/**
173+
* Enable/disable this body's contact response.
174+
*
175+
* @param newState true to respond to contacts (default=true)
176+
*/
177+
public void setContactResponse(boolean newState) {
178+
if (!newState) {
179+
throw new UnsupportedOperationException("Not implemented.");
180+
}
181+
}
182+
183+
/**
184+
* Test whether this body responds to contacts.
185+
*
186+
* @return true if responsive, otherwise false
187+
*/
188+
public boolean isContactResponse() {
189+
return true;
190+
}
191+
172192
public boolean onGround() {
173193
return character.onGround();
174194
}
@@ -279,6 +299,7 @@ public void read(JmeImporter e) throws IOException {
279299
buildObject();
280300
character = new KinematicCharacterController(gObject, (ConvexShape) collisionShape.getCShape(), stepHeight);
281301
setGravity(capsule.readFloat("gravity", 9.8f * 3));
302+
setContactResponse(capsule.readBoolean("contactResponse", true));
282303
setMaxSlope(capsule.readFloat("maxSlope", 1.0f));
283304
setFallSpeed(capsule.readFloat("fallSpeed", 55.0f));
284305
setJumpSpeed(capsule.readFloat("jumpSpeed", 10.0f));

0 commit comments

Comments
 (0)