how to make a character crouch and run in BGE

hi guys i’ve been searching for a good answer around the web for few hours now

how to make character run and crouch ,all i find is the basic movement nothing about

runing or crouching so pleas help me out guys

and is it possible to crouch with just a camera and cube if you know what i am saying ? :smiley:

Hi Othman,

For the running thing, you could do it with logic bricks :

Walking : Keyboard Sensor W key -------- AND controller ------- Character Movement with walking speed ( X or Y axis)

Running : Keyboard Sensor W key -------- AND controller ------- Character Movement with running speed
Keyboard Sensor Shift key —/

For the crouching, you can do the same thing, but move your camera on the Z axis when a key is pressed, and move it back up when the key is released.

Keyboard Sensor Ctrl key, Use Tap activated ----- AND controller ------- Character Movement on Z axis (-1)
Keyboard Sensor Ctrl key, Use Tap activated, Inverted ----- AND controller ------- Character Movement on Z axis (+1)

This is the simple way ; you don’t see the transition between states and this is not a toggle.
For more elaborate functions, you’d need to use properties, or to use python.

Cheers,

AB.

1 Like

@@ABelliqueux

thanks but when i crouch the character fall under the floor if you know what i mean it keeps going down how to make it crouch when i press ctrl but when i releas it he go back up ?

Hi Othman, you can use the action editor and then animate the camera moving the Z axis, then use an action logic brick and set it to the action animation and the amount of frames. Keyboard Sensor Ctrl --> And --> Action. This way the camera won’t move below the floor.

@Othman :

I think you forgot to activate the “Tap” button. Activating it will limit the amount of events taken into account to 1.

For the crouch up, you use an inverted keyboard sensor, wich equates to a key release event.

1 Like

BluePrintRandom has a brilliant crouch setup, it`s very simple and you can have bounds to go under objects.

Video on the way, here is a example of a compound actor crouch

something that complicates it slightly, is that you have to raycast up from the actor, to decide if he can stand back up not by checking for obstructions.

C = crouch

A - D = move left/right

Attachments

CompoundCrouch.blend (477 KB)

1 Like

I do have a question about the project you have there, once you move the cubes, they stop after I’ve stopped pressing “D” key. So with a Mouse, how would I go about that?

Are you using actual python code, or there something simple to sort that out in the logic window?

I am using python for ducking, about sliding, try material friction.
(material setting panel) - do it for actor and floor.

if you want to get fancy,

own.localLinearVelocity.x*=.5
own.localLinearVelocity.y*=.5

about the python I am using for ducking.

I remove parent -> move pieces -> reparent pieces to base shape(compound)

each frame that the physics shape needs changing
the logic does not run the script when your standing :smiley:

also when you release duck it casts rays up, so you can’t stand up inside of something and get stuck etc.

1 Like

there must be a simplier method to crouching

if you use a triangle mesh physics, you can use replace physics mesh I think*
but triangle mesh has no bound volume, so things can easily pass through them.

Study my method…?

the ray up on z axis or a sensor above the actor really are necessary,

otherwise your actor can stand up inside a obstacle and then its gonna be baaaad.

Your script works well in my game, even tho i know nothing about python, it was easy to use, Thanks :P.