# Rotation and Size

Hi, everyone:

Currently I’m doing my class project (Modeling and Simulation) using Blender GameEngine.

However I have a problem which must be solved.
I’d like to connect two objects with an arrow dynamically.

Here is my simulation plan:
I have pre-defined 3 objects, Cube1, Cube2, and Arrow.
The Arrow is hidden.

1. Cube1 and Cube2 are moving around until user presses “A” key.
2. When pressing it, two objects stop moving and then Arrow appears.
3. The Arrow is located between two Cubes.

The problem is 3).

I need a python script for 3).
Frankly speaking, I have no idea how to calculate rotations(RotX, RotY, and RotZ ) and sizes (SizeX, SizeY, and SizeZ) for the Arrow.

The desirous scene looks like this:

actually, python doesn’t need to calculate the rotation

[if it did you wouldn’t set it by rotx roty and rotz, you’d set it by a 3 by 3 orientation matrix]

well anyway, this is off the top of my head, and probably wrong in at least one spot

``````import math

cont = GameLogic.getCurrentController()
myobj = cont.getOwner()

cube1 = cont.getSensor("cube1").getOwner()
cube2 = cont.getSensor("cube2").getOwner()

sizeIPOact = cont.getActuator("act")
trackToAct = cont.getActuator("act1")

# the cubes positions
c1p = cube1.getPosition()
c2p = cube2.getPosition()

# does this take 3 args instead of a list?
obj.setPosition([(c2p[0]+c1p[0])/2,(c2p[1]+c1p[1])/2,(c2p[2]+c1p[2])/2])

obj.ipoprop = math.sqrt((c2p[0]+c1p[0])*(c2p[0]+c1p[0])+(c2p[1]+c1p[1])*(c2p[1]+c1p[1])+(c2p[2]+c1p[2])*(c2p[2]+c1p[2]))

# send true pulses to the actuators
``````

so, umm, anyway… I don’t want to explain or fix this script
[you should learn enough to do that yourself]

that said, you will probably have questions about it I don’t want to answer and it will not fully satisfy your problem.

but to explain what it expects, it expects to be connected to two sensors, one from each cube object respectively named cube1 and cube2
[it doesn’t matter the type of sensors or if they pulse or not, they should just be in those other objects and linked to this scripted and named as I just said]

it also expects the object to have a ipoprop property

furthermore, it expects an IPO actuator playing by that property, named “act”

also, a[n edit object] track to actuator named act1