On 29/01/2015 at 00:46, xxxxxxxx wrote:
Thanks Martin,
The thing is even when my object hits a perfectly flat surface - it still shows a slight discrepancy - it shows every collision no matter where in fact.
Anyway, I cobbled this code together - it's a recursive call which takes an incoming position and velocity, and tries to work out all collisions. From looking at it it seems to work - catching small tight corners etc. It also doesn't make use of my manual calculations, but uses ReflectRay entirely. (I've left in the debug code which compares my mypos error though)
If you spot any errors in this - I'd be grateful to learn, thank you.
def getAllCollisions(pos,vel2,count) :
# print vel
predictedPos = pos + vel2
# sourceobj = doc.SearchObject("Null") # The object the ray will start from
targetobj = doc.SearchObject("Cube") # The object the ray collides with
ray = GeRayCollider() # Create a new GeRayCollider object
ray.Init(targetobj, True) # Assign the object to a variable
start = pos
direction = vel2.GetNormalized() #The direction the ray points.
raylength = 1000
CollisionState = ray.Intersect(start, direction, raylength)
if CollisionState:
print '........................'
hitpos = ray.GetIntersection(0)["hitpos"]
norm = ray.GetIntersection(0)["f_normal"]
distance = ray.GetIntersection(0)["distance"]
if distance < vel2.GetLength() :
norm.Normalize()
reflect = ReflectRay(vel2,norm)
mypos = hitpos + ( reflect.GetNormalized() * (vel2.GetLength() - distance) )
print mypos
print pos + reflect # correct value ?
vel2 = reflect
count += 1
if count < 10:
vel2 = getAllCollisions(pos,vel2,count)
return vel2