So what I am asking is WHILE, the game engine is running, is it possible to change the current pivot point origin of an object to a new location of the object, I'm making a car game and i want to set the pivot point on the left when I'm turning left, and to the right when I'm turning right. Is this possible while the game engine is still running?
3 Answers
When you mean the object's origin: No, you can't (and it makes no sense).
When you mean the rotation center, you can:
- combine the rotation with a translation (= orbiting)
- parent the object to another that acts as rotation center. Turn the parent rather the child.
When you mean the pivot point of a a rigid body constraint, I do not know. The API does not look like you can. An alternative would be to remove the current constraint and create a new one with the pivot at the new location.
-
$\begingroup$ I agree using a pivot empty would absolutely be the way to go. Think tho, in theory, changing origin could be done via transforming verts of MeshProxy and moving local matrix accordingly. $\endgroup$ Commented Mar 22, 2018 at 8:41
-
$\begingroup$ alright that makes sense thank you for your help. $\endgroup$ Commented Mar 22, 2018 at 19:25
people don't give the bge enough credit...
import bge
cont = bge.logic.getCurrentController()
obj = cont.owner
def increase_origon_point(CONSTANT):
meshList = obj.meshes
mesh = meshList[0]
vert = mesh.getVertex(0, 0)
xyz_Pos = [vert.x, vert.y, vert.z+CONSTANT]
vert.setXYZ(xyz_Pos)
vert = mesh.getVertex(0, 1)
xyz_Pos = [vert.x, vert.y, vert.z+CONSTANT]
vert.setXYZ(xyz_Pos)
vert = mesh.getVertex(0, 2)
xyz_Pos = [vert.x, vert.y, vert.z+CONSTANT]
vert.setXYZ(xyz_Pos)
vert = mesh.getVertex(0, 3)
xyz_Pos = [vert.x, vert.y, vert.z+CONSTANT]
vert.setXYZ(xyz_Pos)
increase_origon_point(.1);
shoutout to batFINGERfor giving me the idea. Thanks bro.
-
$\begingroup$ This is a great idea, but please keep in mind that this will not update the physics simulation $\endgroup$ Commented Aug 6, 2019 at 22:57
-
-
$\begingroup$ If you take a plane on z=0 and enable collision, move all vertices to z=1 with Python and let some cubes fall on it, they will still fall to z=0 and not to z=1. Only the visible mesh gets transformed. $\endgroup$ Commented Aug 7, 2019 at 10:45
-
$\begingroup$ ``` you are absolutely right. thankfully there's an easy fix. set that object as the visible layer and put an alternate bounding box around it. You can do so simply with: object = scene.addObject("Alternate_collision_box","Alternate_collision_box") v1 = mesh.getVertex(0, 0) v2 = mesh.getVertex(0, 1) v3 = mesh.getVertex(0, 2) v4 = mesh.getVertex(0, 3) object.worldPosition=(((v1.x+v2.x+v3.x+v4.x)/4),((v1.y+v2.y+v3.y+v4.y)/4),((v1.z+v2.z+v3.z+v4.z)/4)) to calculate the center. But I'm not going into any more details because that wasn't the question. ``` $\endgroup$ Commented Aug 7, 2019 at 23:59
You can update physics mesh using this line of code!:
c.owner.reinstancePhysicsMesh()
Note: This only works with triangle mesh bounds