The Easiest Movement/MouseLook Set-Up Possible for BGE 2.5X! (NO ACTUATORS REQUIRED!)

You guys are going to love this. I just finished scripting the easiest set up possible.
My script, doesn’t even require actuators! To my knowledge, I think I’ve made the
best movement script out there… :wink:
(yay!)

Movement:

import bge
from bge import logic
from bge import events

cont = logic.getCurrentController()
obj = cont.owner

collision = cont.sensors["Collision"]
key = logic.keyboard.events

WKEY = key[events.WKEY]
AKEY = key[events.AKEY]
SKEY = key[events.SKEY]
DKEY = key[events.DKEY]
SPACEKEY = key[events.SPACEKEY]

yMove = 0.0
xMove = 0.0
xForce = 0.0
yForce = 0.0

if AKEY == 3:
    xMove = 0.0
    xForce = 0.0
if DKEY == 3:
    xMove = 0.0
    xForce = 0.0
if AKEY == 2:
    xMove = -0.1
    xForce = -300
if DKEY == 2:
    xMove = 0.1
    xForce = 300
if AKEY == 1:
    xMove = -0.1
if DKEY == 1:
    xMove = 0.1
    
if WKEY == 3:
    yMove = 0.0
    yForce = 0.0
if SKEY == 3:
    yMove = 0.0
    yForce = 0.0
if WKEY == 2:
    yMove = 0.1
    yForce = 300
if SKEY == 2:
    yMove = -0.1
    yForce = -300
if WKEY == 1:
    yMove = 0.1
if SKEY == 1:
    yMove = -0.1

if SPACEKEY == 1 and collision.positive:
    obj.applyForce([xForce, yForce, 300], 1)

obj.applyMovement([xMove, yMove, 0.0], 1)

MouseLook:

import bge

cont = bge.logic.getCurrentController()
object = bge.logic.getCurrentScene().objects
camera = object["Camera"]
cube = object["Cube"]

mouse = cont.sensors["Mouse"]

width = bge.render.getWindowWidth()
height = bge.render.getWindowHeight()
pos = mouse.position
xPos = int(width/2) - pos[0]
yPos = int(height/2) - pos[1]

camera.applyRotation([yPos*0.001, 0.0, 0.0], 1)
cube.applyRotation([0.0, 0.0, xPos*0.001], 1)

if not mouse.positive:
    xPos = 0
    yPos = 0

if pos != [int(width/2), int(height/2)]:
    bge.render.setMousePosition(int(width/2), int(height/2))
else:
    xPos = 0.0
    yPos = 0.0

Hehe,that is cool, its better to you to set up a blend and make a thread on the game engine resources, because if its all that you are saying this ll be great, so far the best mouse look was the raider mouselook!

A couple ideas,

Does applyMovement apply a translation? I don’t think you should be using it for movement if it does, you’re better off just using force like you’ve got for the jumping. You could also think about limiting max velocity and applying a dampening force when none of the keys are pressed (to stop the player sliding).

As for the mouse look, you can remove the mouse sensor by using bge.logic.mouse and you should use bge.logic.getCurrentScene().active_camera to get the camera.

Stuff like this would be good as a component.

Good point! I’m trying to use the bge.logic.mouse right now - the active_camera was a good idea!