How to 3rd person ball controller that can look up and down?

This has virtually no impact on performance. I already had a replay system in my Helicopter demo

so this was not too complicated. This code here saves the Player’s position every second and on key press T he will be repositioned to the position 5 seconds ago.

import bge
cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
own = cont.owner

keyboard = bge.logic.keyboard
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED  
player = scene.objects['Ball']
### how many seconds to jump back
seconds=5

if not 'init_time_jump' in own:
    own['init_time_jump']=True
    own['time_jump_timer']=0
    own['time_jump_List']=[]
 
if len(own['time_jump_List'])==seconds:
    own['time_jump_List'].pop(0)
    
if own['time_jump_timer']==0 and len(own['time_jump_List'])<seconds:
    own['time_jump_List'].append(player.worldPosition.copy())
    
if own['time_jump_timer']==60:
    own['time_jump_timer']=0
else:
    own['time_jump_timer']+=1    

### edit this for a different key
if JUST_ACTIVATED in keyboard.inputs[bge.events.TKEY].queue:
    player.localLinearVelocity*=0
    player.localAngularVelocity*=0
    player.worldPosition=own['time_jump_List'][0]
    own['time_jump_List'].clear()
    own['time_jump_timer']=0

You can change the duration here:

### how many seconds to jump back
seconds=5

The code is conected to an always sensor. I left out a keyboard sensor (to keep logic bricks uncluttered), if you want to change the key then edit this line:

### edit this for a different key
if JUST_ACTIVATED in keyboard.inputs[bge.events.TKEY].queue:

Here is a list of key events:
https://upbge.org/docs/latest/api/bge.events.html

This feature is now included in the updated vWorld file.

1 Like