# How to attach the Character to a moving base

I'm trying to create an elevator, I use Character's physics, Character goes up normally with the elevator, but when descending it goes down slower than the elevator, I already used a script to increase gravity, and Character got heavier than the elevator, however, when he steps in the elevator during the descent, the character bounces. I tried to parent them, but I couldn't get Character to respect the collision of the elevator walls. And I realized that it is also a problem for me to create a platform that moves, because the Character keeps falling due to the speed. Thank you for your time, God bless you!

• When I was using the game engine and came up against this, I had to add an invisible ceiling to elevators and parent them to it. Not a very elegant solution but it kept their feet on the floor. :) Mar 10 '20 at 12:35

I think this is what you are looking for : walk around and stick to animated objects.blend

Video showing the following script in action here

THIS SCRIPT DOES NOT WORK WELL WITH CHARACTER PHYSICS!

# Walk and stick on animated objects and planets v3
# by cotaks

# w,s,a,d and spacebar to move

# able to walk speheres and animated objects:
# like elevators/platforms/planets/beveled cubes/etc.
# when you jump off one of the objects, it will automatically turn +z axis back up

# have fun with it.

from bge import logic

# from player origin to the floor
heigth_offset = 1.0

# length of the raycast
# increase this to be able to jump higher before falling of an object
# (also tweak jump force(brick) and (lower) gravity force)
ray_distance = 0.5

# creates some player gravity, default 30.
# (lower ables to jump off objects, higher means you can jump at all sides of the object)
# adjust the player jump force(brick), or adjust the gravity_force, i suggest keeping it 20+
#just experiment around with it till you are statisfied with the results
gravity_force = 30

def cast_ray(own, vector):

total_distance = ray_distance + heigth_offset
return own.rayCast(vector, own, total_distance)

def stick_to_it(cont):

own = cont.owner

vector_z    = own.worldPosition - own.worldOrientation.col[2]
ray_z       = cast_ray(own, vector_z)

if ray_z and ray_z[0] is not None:

# this could be usefull if you use python for movement, stops the sliding
# if you use this make sure you add a + to line 48 and 49 (so it becomes +=)
#own.linearVelocity.x = 0
#own.linearVelocity.y = 0

# creates some player gravity
vector = -own.worldOrientation.col[2] * gravity_force
counter_gravity = own.applyForce(vector,False)

# match our speed with the ground speed (add a + before the = if you use the above code)
own.linearVelocity.x = ray_z[0].linearVelocity.x
own.linearVelocity.y = ray_z[0].linearVelocity.y

# align to the floor
own.alignAxisToVect(ray_z[2],2, 0.3)

# counters default gravity stops sliding down from the sides with player friction at 0
# if you use player (material) friction (default 0.500) then you can remove this line
own.applyForce((0,0,9.8*own.mass),False)

else:
# put head (z axis) back up
own.alignAxisToVect([0,0,2],2, 0.1)

def update_physics(cont):
# for the (animated) object(s), or any object that needs to update it
# (if you want to walk on animated objects(with bones) they need this part)
# always(true pulse)-python(module)-scriptname.update_physics
# if you have multiple animated objects, your better of making using for loop here
# if you use it remove the own.reinstancePhysicsMesh() and uncomment the for loop code
# with the for loop the animated objects needs a property called: update_physics
own = cont.owner
own.reinstancePhysicsMesh()

#    if not 'update_list' in own:
#        own['update_list'] = [obj for obj in own.scene.objects if 'update_physics' in obj]
#
#    for obj in own['update_list']:
#        obj.reinstancePhysicsMesh()