Prevent character physics types from being moved by player


I’ve set up both my player and npc’s to be Character physics types, since most of the other parameters that Dynamic would offer are not needed for them. However, this means that the player is able to push around the npc’s by walking up to them, even when they are physically many times larger (which looks a bit weird). Is there a way to prevent this?

Ideally, I’d like to keep (at least) the player set to Character physics and set up each npc type to be within a ‘weight’ class, i.e. large = immovable by player, small = pushable. All of the npc’s move around and follow dynamic paths, so unfortunately they can’t be set to static.

I have tried changing them all to dynamic and setting the mass to a high value, setting the friction, gravity etc, but the behaviour is still the same. Does anyone have any advice?


“most of the other parameters that dynamic would offer are not needed for them”, but you’re asking for a weight class and more accurate physics. What gives? You’re the one who chose this life!

Seriously now, character physics is pretty much alien to the concept of mass unless dealing with statics. Make the player and npcs dynamic, problem solved.

But if you’re that stubborn about it you could try to detect when the player is close enough to an npc to push it, then stop applying any further movement in that direction. Simple in theory but applying it can get tricky, and still not really what you’re asking for.

NINJAEDIT: Forgot a few things.

applyMovement(), Simple Motion loc, and worldPosition change are all non-physics calculations.

you need to use forces. applyForce, applyTorque, and Motion force/torque.

applyForce doesn’t work on objects with character physics. I mean, not any time I’ve tried.

i usual put the NPC’s in there own Collision Group that differs from the player.

Thanks for the replies. In the end I added a collision sensor (to detect a player-specific property) to each npc and then in Python set an npc class variable that records the character position (set every frame if there is a collision) and compared that variable to the current world position. If there is a difference, the current world position is updated to the last one. To accommodate for weight classes, I’m using a function similar to this to merge the current pos / last pos based on a value between 0-1. If 1 then they will be easily pushed by the player, if 0 then they will stay in place.

def blendWP(current_pos, prev_pos, blend_amt):

	wp = ((1-blend_amt) * prev_pos[0]) + (blend_amt * current_pos[0]), ((1-blend_amt) * prev_pos[1]) + (blend_amt * current_pos[1]), ((1-blend_amt) * prev_pos[2]) + (blend_amt * current_pos[2])

	return wp

All other npc movement is calculated in Python after this function, so this does not effect movement / pathfinding.