Linked objects
Blitz3D Forums/Blitz3D Programming/Linked objects
| ||
Hi, I am trying to create link system that will take two objects and link them.. so that as they move or fall they will pull and push each other so that they stay about the same distance apart from each other and in the same position relative to each other. I want to use these forces with translateentity. If I use moveentity or and other command it breaks the rest of my program. I simply have Forcex# Forcey# ForceZ# Entity1, Entity2 (blitz3d entities) weight1# weight2#. weight of each object Xdist# Ydist# Zdist# (these are original distances stored at creation, distances from entity1 to entity2) SpringX# SpringY# SpringZ# (ise these for bounce effect from collisions) Currently I have to make 2 instances of the link type to link 2 objects. Once call will link object 1 to object 2, then the next call will link object 2 to object 1. Forces are applied to each object through a loop. I currently have bounce, and collisions working, but the objects will not keep their orientaton to each other I am not trying to make any kind of real physics here. so please no complicated maths. I just want some bouncing objects that keep their formation. Oh and they do collide with blits collision system., meaning I am trying to set it up so that if one object is stuck, the first object cannot pull it and therfor will not move either. Im sure this very simple fix, Any help would be appreciated. |
| ||
Here's how I do it in my physics system:deltax#=EntityX(entity2,True)-EntityX(entity1,True) deltay#=EntityY(entity2,True)-EntityY(entity1,True) deltaz#=EntityZ(entity2,True)-EntityZ(entity1,True) d#=Sqr(deltax#*deltax#+deltay#*deltay#+deltaz#*deltaz#) div#=(d#-Relaxd#)/(d#*-(mass1#+mass2#)) tmass#=mass1#+mass2# m1#=-mass1#/tmass# m2#=-mass2#/tmass# PositionEntity entity1,EntityX(entity1,True)+div#*deltax#*m1,EntityY(entity1,True)+div#*deltay#*m1,EntityZ(entity1,True)+div#*deltaz#*m1,True PositionEntity entity1,EntityX(entity1,True)-div#*deltax#*m2,EntityY(entity1,True)-div#*deltay#*m2,EntityZ(entity1,True)-div#*deltaz#*m2,True You might think this is "complicated maths", but this is not an especially easy topic. Oh yes, and relaxd#=sqr(xdist*xdist+ydist*ydist+zdist*zdist). This should only be done once, as it's a costly calculation. You can probably substitute mass with wheight(wheight is the acceleration imaparted by mass). |
| ||
thanks |