Hello
Im trying to make a First person game. Its like deathrun/kreedz if anyone have played cs 1.6 befor. You need to avoid traps and jump over obstacles to reach the goal.
I need help with a fps mouse and movment script where you can jump like cs or almost like it. I have tried alot of different scripts but all of them are wired where the gravity is all wrong. You either jump to high and take forever to land or the opposite.
Thank you in advance
Some screen shots from the game. Pretty simple build, those blocks vanish for few sec after you touch it. Im not the best at texture, for start i just want the game to work will put more efford in the texture and map after that.
Did you try with a “Character” physics type? In the physics panel you set your player object to be a “Character” physics type. Then you can add a “Motion” actuator, choose “Character Motion” as motion type, toggle the “Jump” button and you have your action ready to be triggered. A temptative script for a FPS controller with a Character could be this:
import bge, mathutils
MOUSE_MOVE_THRESHOLD = 0.01
PRESSED = bge.logic.KX_INPUT_JUST_ACTIVATED
DOWN = bge.logic.KX_INPUT_ACTIVE
ROT_SPEED = 1
MOV_SPEED = 0.1
JUMP = bge.events.SPACEKEY
FORTH = bge.events.WKEY
BACK = bge.events.SKEY
LEFT = bge.events.AKEY
RIGHT = bge.events.DKEY
def signum(i): return (i > 0) - (i < 0)
def axisState(evt, a, b): return (evt[a] == DOWN) - (evt[b] == DOWN)
_vec = mathutils.Vector((0,0,0))
def update(controller):
global _vec
tpf = 1 / bge.logic.getLogicTicRate()
body = controller.owner
character = bge.constraints.getCharacter(controller.owner)
head = bge.logic.getCurrentScene().active_camera
mouse = bge.logic.mouse
keys = bge.logic.keyboard.events
dmouse = (mouse.position[0] - 0.5, mouse.position[1] - 0.5)
drz = (abs(dmouse[0]) > MOUSE_MOVE_THRESHOLD) * signum(-dmouse[0])
drx = (abs(dmouse[1]) > MOUSE_MOVE_THRESHOLD) * signum(-dmouse[1])
body.applyRotation((0,0,drz * tpf * ROT_SPEED), True)
head.applyRotation((drx * tpf * ROT_SPEED, 0, 0), True)
movey = axisState(keys, FORTH, BACK)
movex = -axisState(keys, LEFT, RIGHT)
_vec[:] = (movex * MOV_SPEED, movey * MOV_SPEED, 0)
v = _vec * body.worldOrientation.inverted()
character.walkDirection = v
if keys[JUMP] == PRESSED: character.jump()
mouse.position = (0.5, 0.5)
Here the camera is attached to the Character-body object and works as a separate head for the player, to look up or down (you need a constraint to limit the amount of rotation of the head)
With a dynamic object, the path described by the jumping object is just a matter of force, gravity (and damping). You control how high it jumps with the top-down value of the force (z axis for example) and how far it jumps by applying an x-y value transformed by the orientation of the jumping-body.