drive object along surface, sticking to it
Blitz3D Forums/Blitz3D Beginners Area/drive object along surface, sticking to it
| ||
i want to drive a 'car' along an object's faces. i can do this by pulling the car down (relative to car), and if there's an incline, he collides and slides up but i want him to be able to drive on any surface, even the outside of a sphere or inside a twisty track with loops. so, the car needs to align itself with the surface it is driving on. What is the fastest (processor time) way to do this? somehow measure distance from edges of car down to surface, and adjust the vehicle so that those edges are about even somehow? i am not certain how to do this. i explored the car demo, i understand basically how it works, but is that the best way - with 4 collision pivots at the wheels? (I don't have wheels on the vehicle but just the same) my vehicle does collide already in one spot with the object its riding on, can i somehow align with the surface i've collided with? a little clueless as what to try! thanks |
| ||
Find the collision normal (collisionnx,collisionny,collisionnz) commands, then use aligntovector on your object, aligning the y-axis of your object to the collision normals. |
| ||
thanks! i wonder though - how come just the y axis? it seems that if the road is going not just up and down but twisting around (barrel rolls), i'd need to align every axis? hmm ok maybe not roll. is there code for this somewhere? |
| ||
i'm baffled i've got this ny#=CollisionNY#(carpiv,1) nz#=CollisionNZ#(carpiv,1) nx#=CollisionNX#(carpiv,1) AlignToVector carpiv,nx,ny,nz,0 i've tried every number at the end and various combinations of them, sort of just guessing here. mostly what happens is the car at start gets flipped on its side, or up. I think I see some angling of the car on inclines though. the carpiv is located below the car. it's facing 'forward' just like the car. it touches the ground. to move forward I add to Z. I assume that's relevant to what we align. when i move the car, i actually move carpiv because carpiv is parent. i rotate the car to turn, but never rotate the carpiv because i wanted left and right and up and down on keyboard to match the carpiv's movement (so that when you push up no matter how car is rotated, the car moves 'forward' as far as the camera is concerned) i am lost as to how to make this right. |
| ||
You've used 0 for the axis param - it should be 2, for the y axis. Also, I think you may need to invert the normal: AlignToVector carpiv,-nx,-ny,-nz,2. [edit] actually, I'm not sure about the inverting the normal thing - my brain is currently working on minimum power, for various reasons. :) |
| ||
hmm no, that doesn't seem to do it either. i tried AlignToVector carpiv,-nx, ny,-nz,2 because -ny makes the car flip upside down. but it's still not doing the trick. any ideas? |
| ||
well, i got other objects in my game to work using nx#=CollisionNX(e\piv,1) ny#=CollisionNY(e\piv,1) nz#=CollisionNZ(e\piv,1) AlignToVector e\piv,nx,ny,nz,2,1 but not my car, so must be something with the goofy way i set up the car! |
| ||
i am completely baffled. some objects seem to be controlled by this properly and others are not. the ones that are not controlled properly are angling about half the amount they should. i know this isn't much to go on but is there any way i could be getting about half the amount from the collisionNX/NY, etc than I expect? |
| ||
try a linepick? |
| ||
Firstly, you need to make your track pickable, by giving it and EntityPickMode of 2. Then, every loop, do a linepick straight down from the entity's position. Use TFormVector, to make sure the linepick points downards, relative to the entity. |
| ||
Your collision index is constant - if there's any way that collision 1 might not actually be between a particular object and the scenery (say object to object instead) then that might explain it. Also, I would make the rate correlate to the velocity of the object to be aligned. |
| ||
i don't see where entitycollided comes into play. here's basically what i've gotcc=CountCollisions(carpiv) If cc>0 If cc > 1 DebugLog cc+" collisions for car" delay 500 EndIf for i=1 To cc obj=CollisionEntity(carpiv,i) t=GetEntityType(obj) Select t Case T_WALL,T_PLATFORM ;align to this obj nx#=CollisionNX(carpiv,i) ny#=CollisionNY(carpiv,i) nz#=CollisionNZ(carpiv,i) AlignToVector carpiv,nx,ny,nz,2,1 ;now i do basic movement end select etc i'm not using entitycollided, should i be? there doesn't seem to be any clear examples of how to do collisions correctly and completely. by the way i do get multiple collisions with carpiv and ground/walls, at the same time. |
| ||
t=GetEntityType(obj) Select t Case T_WALL,T_PLATFORM I'm pretty sure EntityType doesn't return an entity... |
| ||
Should be ok Ross, it just references the collision type of that entity. Show us the code and we'll try and fix it. |
| ||
is there code for this somewhere? http://blitzbasic.com/codearcs/codearcs.php?code=1069 |
| ||
i'm using exactly that same technique, however my car falls through 'vertical' walls once they reach a certain steepness, it seems. it loses collision detection of the wall that it is on. it's pushing 'down' on it (which is against the vertical wall) just slightly (simulating a local gravity) i checked the normals, the object is not inside out. very confused. i see that the example works but can't figure why mine does not. |