How do you push an object?
Blitz3D Forums/Blitz3D Beginners Area/How do you push an object?
| ||
Hi, I played today with Elias_T coldet wrapper, and liked it. Once a collision occurs, how would I push away one of the objects? This is for a really simple racer, wo. complex physics. Thanks for reading, and of course, for help. |
| ||
Something simple would be to use the direction of the car and move the object B using this direction with MoveENtity. You could then implement some kind of inertia: moving the car: ... Moveentity car,0,0,speed ... if crash: rotateentity rock_pivot,0,entityyaw(car),0 rotateentity rock,0,0,0,1 rock_speed=speed endif somewhere else you'll update all objects that are in motion (other than cars): if rock_speed>0 then moveentity rock_pivot,0,0,rock_speed rock_speed=rock_speed *0.9 if rock_speed< 0.05 then rock_speed=0 endif Note rock_pivot is the parent of rock, You need it to be able to move the rock away from the car without to alter the rocks current rotation. Speed and rock_speed are floats. For simplicity you may use a type structure or arrays to hold all objects like rocks or things that may be pushed, So you'd have an array for all rock entities, their additional pivots, their speed, etc. so you could handle them in a FOR/NEXT loop by index easily. |
| ||
Jfk EO-11110, thank you for your code. I will play with the cars masses to determine which car moves which (all subjective). With inertia, it does look better and feels better. Thanks again. |
| ||
uh there was a "bug" in my "code", of course you need to MoveEntity rock_pivot,0,0,rock_speed, instead of rock. (Just fixed it) |
| ||
hehe, thanks for the fix :) Unfortunately, seems coldet stores everything in original position, maybe I am missing something, because after push, even obect 2 does get pushed (and so represented visually), if I leave my car where collision occured, it stills gets pushed. Anyhow, thanks. |
| ||
Sorry, I missed this. What you say sounds like the friction factor isn't high enough. Try something like: rock_speed=rock_speed *0.5 if rock_speed< 0.05 then rock_speed=0 instead. I don't know how coldet affects the entity position system, but I guess it shouldn't be a problem to move an entity. Just watch my source an see what it does: When the camera touches a rock, it will give the rock a certain energy and move it in one direction as long as this decreasing energy is zero. No big deal, should be easy to implement. Tho, if you want the rock to be able to push other rocks and so on then you maybe better use a physics library, such as one of the ODE interfaces, or tokamak. |
| ||
hi jfk :) Code actually does move the object out of its original place, but for some reason collisions aren't detected anymore in new place, but as if it wasn't never moved. Maybe I'm using coldet badly, to me it seems the positions are stored where original mesh was placed. So pretty much I ended using one function found in the library (dynamic collisions). It isn't precisely what I wanted but for now it does it's thing, maybe with some modifications I will be able to calculate different reactions based on masses (500 > 300, so move 300 a lot, not so much the 500 one). For now I'm stuck making models, so left this for somewhat later on. Thanks for checking by. |