I 've been taking a break and got rusty so I need your help.

I have an integer property with a random first value.I want to somehow connect it to the length of a plane, so that when the integer property decreases the plane's length will decrease the same percentage.

For example if the first value of the property was 100 then every second that passed the integer would be subtracted by 1 so the plane would lose 0.01.

If the first value was 20 then it would lose 0.05.

I 've found some tutorials where the plane would get animated but they did not quite help. Any ideas on how to procceed?

  • $\begingroup$ What is the leading data, the length of the plane or the value of the property? Do you calculate the decrease from the initial value or is it a fixed percentage, or is it a percentage of the current value? $\endgroup$
    – Monster
    Feb 26 '16 at 7:45
  • $\begingroup$ The length of the plane is fixed. The value of the property changes constantly like a timer going downwards (but with integer values). So the length of the plane should lose each second : (initial length of plane) / (initial property value) --> fixed percentage . I hope I made it clear. It will serve as a battery life bar , like the ones in our mobile phones. $\endgroup$
    – Lev
    Feb 26 '16 at 8:11
  • $\begingroup$ This means you need logic that processes the "battery life" and something (like an health bar) that shows the current value. $\endgroup$
    – Monster
    Feb 26 '16 at 9:00
  • $\begingroup$ I used logic bricks to perform the first with an always sensor(set to 60 for the seconds) and an actuator decreasing the initial value of the property. I need help in the process with the "health bar". How will I change the length(distance of vertices) considering the percentage, etc. $\endgroup$
    – Lev
    Feb 26 '16 at 9:19
  • $\begingroup$ It is not a propert answer towards the SE rules. I suggest to look at BGE Guide to Messages incl. Healthbar tutorial: blenderartists.org/forum/showthread.php?249078 $\endgroup$
    – Monster
    Feb 26 '16 at 10:31

enter image description here

The following script runs every second when the light is on. I used an always sensor with "60" placed on the frequency. Since I am interested only in the plane's vertices I won't say more about the logic bricks.

import bge

scene = bge.logic.getCurrentScene()
controller = bge.logic.getCurrentController()
object = controller.owner
#sensor = controller.sensors["name"]

# Get a list of the mesh
meshList = object.meshes
# Get the first mesh on the object
mesh = meshList[0]
# or mesh = object.meshes[0] for both lines

# get the 2 vertices in the right side of the battery
verttop = mesh.getVertex( 0, 2)
vertbot = mesh.getVertex( 0, 1)

# new xyz for the vertices
# 0.09 is a result of the following:
#length of battery(180cm)/time it should work(20s)
verttop_xyz_Pos = verttop.getXYZ()
verttop_xyz_Pos[0] = verttop_xyz_Pos[0]-0.09
vertbot_xyz_Pos = vertbot.getXYZ()
vertbot_xyz_Pos[0] = vertbot_xyz_Pos[0]-0.09

# set local xyz position of the vertices

This solution worked for me. So till anyone finds a drawback, here it is.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.