aligned to the terrain not using "rigid Body"

hi, I’m making a car game, similar to Mario kart where the cars don’t flip. First i try using rigid body with vehicle constrain, it works really good but its like a real car , so if you go too fast and crash with a wall you would probably go up into the air and maybe even flip the car.
I found that using just dynamics with animation would do the trick with a plane ground , but with a ground with bumps and hills, it doesn’t work.
i made some test using 3 empties that have a ray sensor calculate the points where they hit the ground some math vectors and rotations… and i found a way to rotate cars with the ground. The only thing its that its really difficult to put everything so it doesn’t brake, a lot of research and a better script.
So maybe I’m doing all this in vain because somebody have a better idea or even better a Solution :eyebrowlift:.
just in case here is the script

import GameLogic
import Blender.Mathutils as mat
import math
con = GameLogic.getCurrentController()
own = con.getOwner()
List =objList = GameLogic.getCurrentScene().getObjectList()
def pointVector(A,B) :
 ret = [A[0]-B[0],A[1]-B[1],A[2]-B[2]]
 return ret
def productoVectorial(B,A) :
 X = A.y*B.z-A.z*B.y
 Y = A.x*B.z-A.z*B.x
 Z = A.x*B.y-A.y*B.x
 return mat.Vector(X,-Y,Z)
def normal(A) :
 s=math.sqrt(A.x*A.x + A.y*A.y + A.z*A.z)
 return A
vecN1= mat.Vector(pointVector([point1.x,point1.y,point1.z],[point2.x,point2.y,point2.z]))
vecN2= mat.Vector(pointVector([point1.x,point1.y,point1.z],[point3.x,point3.y,point3.z]))
vecNorm= normal(productoVectorial(vecN1, vecN2))
vec1=normal(productoVectorial(vecN1, vecNorm))
R = own.getOrientation()
R01 = R[0][1]
R11 = R[1][1]
R[2][0] =vecNorm.x
R[2][1] =vecNorm.y
R[2][2] =vecNorm.z
R1 = [[vec1.x,vec1.y,vec1.z], [vec2.x,vec2.y,vec2.z],[-vecNorm.x,- vecNorm.y,-vecNorm.z]]

well you could use just the function i coded and campbel pimped: alignAxisToVect(vector,axis,rate) (available in SVN (trunk and apricot) and 2.47)

you have to put the vector created with ray.getHitNormal() (from a ray pointed to the -z local axis, with pulse mode enabled) the axis is 2 (Z) and the rate may be for example 0.4, if the sensor is not possitive you can just align to [0,0,1] (upright)

that method works, i have a game with a very speedy character and it doesnt fail if the slopes are correctly modeled

btw, your method looks interesting, i was thinking on doing something like that, but i found this method that is very good and easier to implement

thanks cyborg_ar, i didn’t knew about the getHitNormal() :stuck_out_tongue: that makes everything a lot easier because you can use only one empty or 2 if you want a more correct inclination.
I’m using 2.46 , i could change to 2.47 but i´m really new to the blender engine so i don’t know:o.
But alignAxisToVect essential do is to realign the object with the normal? why use rate ?
besides its already done what its the advantage of using this script from realigning it by hand using the setorientation.

Less logic usage. Cyborg_ar coded that function in C++ right (?) Essentially, it will improve the framerate and CPU usage in the long run. Either way, if your game is as simple as you make it seem, there is really no point in undoing all your work already.


yea that function is coded into blender, so its fastest. the rate parameter is for interpolation (smoother motion)

why reinventing the wheel?
i would change to 2.47
thanks nick cyborg_ar

i just tested and it works awesome:p!
this simplify everything
I’m going to study your game cyborg_ar there’s lot of cool thing going inside that game.

well you can check out the latest version of “sonic bastardized” in sage, google it i’m not allowed to put the link here, forum policy XD

This is a great function, however, I’m curious if there is a way to align objects to physics objects. I’ve been trying to get decals working, but they only align correctly on non-dynamic objects. Is there any way around this?

i don’t know about problems about aligning with non-dynamic, but it would be easier if you upload a file with the problem, I’m going out for the weekend so probably i won’t answer but somebody would help you :eyebrowlift:

That’s what I said, there isn’t a problem with static meshes or meshes that are modified by a movement actuator, but if the object is dynamic (has physics enabled) the alignment doesn’t work. Though when I posted the previous comment I forgot that I had determined that the normal returned by the ray was incorrect and that it was not alignToAxis that doesn’t work.
Attached is my wip which is my attempt at an FPS (awsd+mouse controls). Firing at the floor applies the decals correctly as does firing at the spinning cube, however if you push the physics cube around and then shoot at it, the decals are applied at odd angles.


fpsbase2.blend (218 KB)