I'm having some trouble with the alignToVect to the ground


(BluePrintRandom) #22

my system is looking at the normal ahead of the player slightly,

you may think this is over complicated

however I have actually made this before :stuck_out_tongue:


(Cotaks) #23

yes, but remove that other script/brick, my script does that function now as well.(no idea why you need it)

the loop, put property ‘align_player’ on it.
the ground, put property ‘ground’ on it.

so looping will align and when running off and get to floor sonic puts head(z axis) back up.
This wil make sure that if you go up in the air, sonic will not put his head up, only when hitting the ground.

But keep in mind just like the other script if sonic is on his side and falls on the ground it will not put the head back up because the ray won’t get into positive state.

.col[2] grabs the z matrix (0=x,1=y), and [2] grabs just the z from the matrix (correct me if i am wrong here)

if you calculate the angle or convert to euler i believe it needs a matrix (.col[]). you should never use worldOrientation[2](it’s outdated for a few years now) always use worldOrientation.col[2]. but for position you can do worldPosition.z or worldPosition[2]. For really simple things you can use [2] for orientation as well, but as soon as you going to calculate anything with it it will fail sooner or later. to prevent it from failing we grab the column instead. i beliieve it had to do with the changes that where made with the math module/library


(jesusmora) #24

i have also made things work, and you don’t need all those calculations. just use an object or use vectors to calculate a final position for the ray, but don’t do adding like +=, that will only lead to glitches.
i don’t think its necesary to move the endpoint, sonic will rotate and the empty/endpoint will rotate with it. just put the empty at a more forward position, in front of sonic instead of right under him.

there should also be a force pushing sonic against the surfaces, otherwise he will bounce back or fall. a small motion in local Z axis should do it.

to grab the z from the matrix you do [2], to grab the z in the z you do [2][2]. i’ve never used col and i worked with vectors all the time.

i just tested it with a rotating object and it gives different values if i do [2] or col[2], but [2] still returns a vector if i do print:
[2]:
<Vector (0.0000, 0.0000, 1.0000)>
<Vector (-0.4218, 0.5771, 0.6994)>
col[2]:
<Vector (0.0000, -0.0000, 1.0000)>
<Vector (0.6958, -0.1637, 0.6994)>
so the difference is that one gives wrong values?
anyways thanks for telling me, that information is not in the documentation.

are you talking about upbge? i’ve never used the lastest version, it has missing features. 2.2 has broken rays, and the lastest has broken libload. i’m using 2.0 now because it’s the only one that’s not broken. i will wait until they fix the bugs before using a new version.


(PixelSonic101) #25

well I’m using upbge 2.3


(Cotaks) #26

No just BGE.
One thing i know is i regularly came into trouble with using [2], since i started using .col i havent had a single problem with it.


(jesusmora) #27

haven’t used that version. the last version i used was 2.2 and rays were broken, i think they fixed camera frustrum in 2.3? but i’m not sure.
but if you run into the ray bug, this version of the script will take that into account:

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

ray_distance = 2.0
align_speed = 1.0
#speed at wich sonic must turn and face upwards
falling_speed = 0.0
#the speed at wich sonic will wall walk
wall_walking_speed = -0.2

pos = obj.worldPosition
other = scene.objects.get("step")
floor = obj.rayCast(other, pos, ray_distance, "floor", 0, 1, 0)
if floor[0] != None and obj.getLinearVelocity(True)[1] > wall_walking_speed:
     if "floor" in floor[0]:
          obj.alignAxisToVect(floor[2], 2, align_speed)
elif obj.getLinearVelocity(False)[2] <= falling_speed:
     obj.alignAxisToVect([0.0, 0.0, 1.0], 2, 0.5)

the only problem is, the ray will always hit the first object and not just the floor (xray does nothing). maybe it will skip nocollision objects, i’m not sure. but if it hits an object without the property, there will be no errors or glitches.


(PixelSonic101) #28

which one do I put it 1 or 2


(Cotaks) #29

on 1, the whole box that covering sonic, not the two small ones.


(PixelSonic101) #30

I tried using the script there’s a problem


(jesusmora) #31

are you using my script? have you done this:


(Daedalus_MDW) #32

why use an object?

get position relative to owner
step = owner.worldPosition + owner.getAxisVect((0, 0.1, -1))


(jesusmora) #33

nice, maybe aim a little more forward, also, the sonic in the screenshots is looking at a negative Y:

step = owner.worldPosition + owner.getAxisVect((0, -0.4, -1))