# Character Slopes Alignment

So I looked into it and used a video I found that uses constraints on the Z axis to keep the player aligned to the ground, but when working with the Edit Object - Track To, actuator, it locks all movement no matter what I do.

I can’t find any fix or work around besides: Learning a new way to have camera relative movement or not use constraints to align the player to the ground. If anybody knows how to fix this, I’d really appreciate it.

The type of game I’m making is a 3D platformer.

Here’s a video (Thanks to you guys for your help too!) https://www.youtube.com/watch?v=awAfU5l6FH8

align feet bone root to hit normal,

or,

place a target using a ray, in front of the player, have a item track to it that is at the center of the two feet in idle.

Parent feet ik bone handles to a bone, have the bone at the same location as “track to” item. do copy rotation from bone to the tracker.

Will that work? I’m not sure we’re getting at the same thing. I’m looking for more something like this:

But that will prove helpful in any later projects I may make. I’m going for like how Sonic games rotate the character according to the angle like in the video. But when using the Edit Object -> Track to “Front” which is a cube in front of the camera which makes the player face in that direction. Then I use Motion -> Linear Velocity -> 0.2 Ad:Local so he moves in that direction. But when using a constraint to keep the player aligned to the slops it won’t let the player move.

This is the tutorial I used for the alignment to slopes: https://www.youtube.com/watch?v=eo6z4gMCJJc&index=12&list=UUUN0JaPGKwix61xRKeBuYKw

align axis to hit normal of ray, is what you will need, that wears off as you slow down(sonic)

something like this maybe but ???

you will need some way to do

what is my rotation?

what is the surface rotation?

rotate over time, but at what rate?

so it has to be python, however, python becomes simpler to achieve if you first start with

Ray------------GameLogic simple template--------actuator

open a new text window, do templates game logic simple.

It helped me a lot,
to get a sensor and actuator “hooked” into python, then manipulate logic at first, and then transition into

1/2 logic 1/2 python depending on if logic can do it or not,

Thank you! I’ll have to look into how this works because I’m still stumbling over it a little but thanks for helping and replying so quick!

``````
import bge

playerobject = bge.logic.getCurrentScene().objects["the playerobjects name here"]

playerdown = playerobject.worldPosition
#I make an inbetween variable, because otherwise it would change the position of the playerobject
downpos = [playerdown[0],playerdown[1],playerdown[2]-2]

hitObject, hitPoint, hitNormal = playerobject.rayCast(downpos, playerdown, .0, property(if you want))
# check the orientation of the wall the player is hanging from and then use it for our own orientation
if hitNrm != None:
# this line below
playerobject.alignAxisToVect(-hitNrm, (the axis(0 = x, 1 = y, 2 = z )), (the speed you want on float))

``````

this piece of code above does all the things the op asked for, checks the surface orientation and uses an inherent property of the KX_GameObject to orientate the object accordingly.

import bge

playerobject = bge.logic.getCurrentScene().objects[“Player”]

playerdown = playerobject.worldPosition
#I make an inbetween variable, because otherwise it would change the position of the playerobject
downpos = [playerdown[0],playerdown[1],playerdown[2]-2]

hitObject, hitPoint, hitNormal = playerobject.rayCast(downpos, playerdown, .0, ‘ground’)

# check the orientation of the wall the player is hanging from and then use it for our own orientation

if hitNrm != None:
# this line below
playerobject.alignAxisToVect(-hitNrm, (z(0 = x, 1 = y, 2 = z )), 10)

I’m not sure if I’m doing it right? I connected this to an always sensor and edited it like this and I don’t get any result. Thanks again for even helping!

@PluePrintRandom:

This is the result of some things that I did, that you suggested: https://www.youtube.com/watch?v=ZvW87-Eb1yQ

playerobject.alignAxisToVect(-hitNrm, (z(0 = x, 1 = y, 2 = z )), 10)

the 10 should be a value between 0 and 1

0( don’t rotate at all) and 1=instant

so you want something like .8?

also -> playerdown = playerobject.worldPosition.copy()

hm with the new things changed I get syntax error: keyword can’t be used as expression- for this line:

playerobject.alignAxisToVect(-hitNrm, (z(0 = x, 1 = y, 2 = z )), 0.8)

EDIT: Now I fixed that error but I don’t get any rotation

playerobject.alignAxisToVect(-hitNrm, 2, 0.8)

want to post a .blend? I’ll check it out?

Okay:

ok here you are sir

http://www.pasteall.org/blend/31032

edit

Replace gamelogic simple with this

``````
import bge
from mathutils import Vector

def main():

cont = bge.logic.getCurrentController()
own = cont.owner

St = Vector ([0,0,-1])
Start = own.worldPosition+(own.worldOrientation * St)
St = Vector ([0,0,-2])
End= own.worldPosition+(own.worldOrientation * St)

hitObject, hitPoint, hitNormal = own.rayCast(End,Start, .0, "ground")
# check the orientation of the wall the player is hanging from and then use it for our own orientation
if hitNormal != None:
own.alignAxisToVect(hitNormal, 2, .8)

main()

``````

Again, thanks a bunch!

No problem, just keep at it !