On 07/01/2015 at 11:08, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R16
Platform: Mac OSX ;
Language(s) : XPRESSO ;
---------
Hi,
Since I'm very sure there isn't something wrong with my code, I put the post in here.
So, I have a file with 2 objects, one who is going to rotate, and a static object.
I have some simple code for if the two objects collide, object A's rotation should go to the previous (captured) rotation. Because of this, the two objects should never be able to collide, when object A is rotating.
Because I can't upload my file, I'll tell how it is constructed:
Two editable objects (A and B). Object A should be able to ratote, and because of that get collision with object B.
In object A there is an Xpresso tag containing the following:
A node for object A, with an output port "Object" connected to the first input port of a collision node.
A node for object B, with an output port "Object" connected to the second input port of the collision node.
The output port of the collision node is connected to a python node with the custom input port "isColliding", an integer.
The second input port of the python node is a vector, "newRotation" which gets its value from a node for object A (the same node or a new one, with an output port "Rotation").
The first output port of the python node also is a vector, "lastRotationOutput", which is not connected with anything.
The second and last output port of the python node again is a vector, "newRotationOutput", which is connected with again a node for object A (note: this cannot be the same node you used at the first or second time), the input port set to "Rotation".
Finally, the code inside my python node:
import c4d
#Welcome to the world of Python
def main() :
global isColliding
global newRotation
global lastRotationOutput
global newRotationOutput
if isColliding == False:
lastRotationOutput = newRotation
newRotationOutput = newRotation
else:
newRotationOutput = lastRotationOutput
#end Python code
The code does the following:
For each new position, the python node checks whether there is collision or not.
If there is no collision, the rotation value gets inside both the lastRotationOutput and newRotationOutput. The object behaves as normal.
If there IS collision, the newRotationOutput (the rotation value that goes back to object A) will be replaced by the lastRotationOutput (the last rotation in which there was no collision), and object A will go back to it's previous state before collision.
My problem now, is that, although they never collide, they also never come near to each other, due to some bug in Cinema 4D, I guess. Even worse, sometimes object A stops rotating a few degrees before colliding, sometimes more, sometimes less. (For example, sometimes it's 24.5°, sometimes it's 12.34°, sometimes 28.67°)
What could be the problem here?
Thanks in advance for your help and time!
Greetings,
Casimir
Andreas: added code tag