Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
I am really confused. I have a tank moving in a 2D space. It can be controlled by w, a, s, d. It's inside a square and I want it to collide with the borders of the square. So this is my code when the tank is moving (executed every frame):
So first I move the tank to the next position on the Z axis. If there is a collision it will be put back to the position of the last frame. Then I do the same thing for the X axis. Now the problem is that the tank completely stops at the wall but I want it to "slide" along the wall. This is the code of my collision function:
The functions checks if the tank's boundingbox collides with 1 of the 4 borders. Please help, it's my first try with Javascript. I need to know how to fix the collisions. Here is the demo if you don't understand what I mean (collisions only programmed for forward movement yet. Turning and moving backwards goes trough wall): http://home.arcor.de/bownz/pete/ |
||||
|
Nice demo. For sliding, you need to calculate a sliding vector and move the tank along that then. Alternatively, you also can just use a CL3D.AnimatorCollisionResponse, this should do anything for you automatically. |
||||
|
Thank you niko. I found out how to fix it. I had to add tankbody.updateAbsolutePosition(); to the first line of my collisioncheck()-function. I don't really understand why because I don't know how getTransformedBoundingBox() is working in detail. It was just a guess. That took me like a whole week but it's working now. |
|