Help ! Any programmers? Or good scripters out there that can help?

Okay. Here’s another crack at this thing.


from bge import logic
import mathutils
cont = logic.getCurrentController()
obj = cont.owner

if not 'endpos' in obj:
    obj['endpos'] = obj.position.copy()

endpoint = obj['endpos'].copy() # Ending position of the camera (beginning position's height - 2 Blender Units)
endpoint.z -= 2

diff = obj.position - endpoint # The difference between the current position and the end point

smooth = 0.5 # How smoothly to slide to the end position

obj.position.x += diff.x * smooth
obj.position.y += diff.y * smooth
obj.position.z += diff.z * smooth


Try this out. If it works, note that you’ll need to set the endpoint when your character isn’t crouched.

This didn’t work either…

Okay, what seems to be the problem? What does the console say? What’s happening?

Well - It runs - but it doesn’t move smoothly - it simply teleports.

Hm. I’ll figure it out and get an example blend out, since my coding examples seem to be going so well (LOL).

lol - SolarLune - that would be appreciated if you can solve the riddle.

Okay. So, here’s the theory in action - press C to crouch, and release it to stand up. It does so smoothly, not ‘teleporting’ about. The script operates on the camera, so make sure you’re in that view to see it. The script is a bit more than necessary, but the theory should be able to be applied to your game.

Crouchtest.blend (430 KB)

Hmm - this doesn’t QUITE work… not yet atleast. We’re getting closer to a solution however… I’m uploading my blend file to show you why this isn’t working…

Firstly - this script will only work for a static camera… not a camera used for a FPS or something - (like what I want to design ) here’s the blend! I hope you can help further SolarLune, you’ve taught me a great deal already.

Attachments

Hyperreal.blend (446 KB)

Okay, I ditched the whole ‘vector subtraction’ that I had in my script for a simpler subtraction of just the Z-axis variable. It works better this time around. Note that I deleted the empty and parented the Camera to a cube so that I could see what was going on - you can turn it invisible, but if you would rather keep your empty, then just use the script - I didn’t change anything else about the setup (I don’t think).

HyperrealFixed.blend (450 KB)

@SolarLune: Thank you very very much for your contribution, I’ve learned a lot from you SolarLune. I’ve learned enough to make my own script which works well. If you are interested, you can take a look below:

import bge
from bge import logic
from bge import events

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

key = logic.keyboard.events
SHIFTKEY = key[events.LEFTSHIFTKEY]

if not 'press' in obj:
    obj['press'] = False
    obj['return'] = False

limit = 1

if SHIFTKEY == 2:
    if not obj['press']:
        obj['press'] = True
        if not obj['return']:
            obj['initz'] = position[2]
            obj['return'] = True
    if obj['initz'] - position[2] < limit:
        position[2] -= 0.1
else:
    obj['press'] = False
    if obj['return']:
        if position[2] < obj['initz'] - .0001:
            position[2] += .1
        else:
            obj['return'] = False