how to set rotation

I am looking to see if I can set an objects rotation to a specific rotation…on one axis(0,0,1)or something…any tips? I’ve been looking in all the regular places, but not finding anything useful…I do not want to deal with an objects entire martix just to lock an axis :slight_smile: as I may need to do this to many objects…I just think it would be simpler if it was just a single command…otherwise I could go another route.

p = own.worldPosition + Vector([X,Y,Z])

v2 = own.getVectTo§

own.alignAxisToVect(v2[1],0,.1)
own.alignAxisToVect([0,0,1],2,1)

I do this same thing, but multiply the vector by the camera.worldOrientation

ok, I had already tried alignAxisToVect, but it does not work as advertised :slight_smile: so I wanted to ‘lock’ the z axis now for an enemy to go back to after the player is outside thier interest zone…I was using a track to as proof of concept, and it works…the problem is, then I need to add very specific objects for npc’s and enemies to track to…and it just piles up on the useless objects…and a very poor way to plan out ai.

on a side note I did it almost exaclty how you have in your code…
where ‘p’ was the players worldPosition + their worldPosition z+1…I will copy paste your code and fiddle with it to see what I did wrong. Thanks.

well your snippet works well…does ‘getVecTo’ normalize the vector or some other magic? I need to go look that up…thanks again.

you + (an offset)

gives you a point to aim at,

object.getVectTo() gives you the angle needed to face that way

well here is what I ended up doing using the vector subtract method…

p = own.worldPosition - Vector([own['home_x'],own['home_y'],own['home_z']])#home is just spawnlocation

            v2 = own.getVectTo(p)
            own.alignAxisToVect(-p,1,1)#to flip the orientation on z...could simplify this but...it's fine

            own.alignAxisToVect([0,0,1],2,1)#and ofc locking the alignment of the actor



typical, but functional…I just need to spice it up a bit for obstacle avoidance…otherwise it works as ecpected…

The issue I have with alignAxisToVect is that it is not singular ‘axis’…I guess I wouldn’t know the difference in spelling ‘axis’(singular) or ‘axis’(plural)…axees :wink:

I do something like this:


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


xyz = own.localOrientation.to_euler()
xyz[2] = math.radians(45)
own.localOrientation = xyz.to_matrix()

source

oh, nice link. I have been avoiding the use of matricies, or multidimensional arrays…I tend to get lost in my code when it gets too complex…kids running around screaming etc :)…don’t forget I am old :wink:

besides the other way makes it much easier to track arbitrary vectors…be it way points indexed or object locations. My initial question was a bit vague, I admit. I try not to advertise to much what I am doing…I really would like to have something more refined before I start to show anything.