2 newbie questions - is it possible to change size/radius....

Hi,

is it possible to change object properties like size/radius in Blender Game Engine? I know that in “normal” Blender there are some functions, but Blender library wont work when I export my game into exe file.

Little background what I am trying to do: I have some equations in python that I am using to animate ball, so I am not using BGE dynamics or anything. Now I want to interactively change variables, and I want BGE to change it graphically as well - through python script. I checked some some class list etc. but only thing I found was function getMass(), which isnt exactly what I need, because I also need some set- thingies.

And other question: I have ball, and I created thread/string using circle object. How can I stationary fix one end of thread into “air” (or anywhere) and the other end to ball so when I animate it it will look like pendulum? I tried to join both objects to one, but I still have problem how to fix the other end

to change the scale you can use this. (to set the scale of the object the script is attached to)

own = GameLogic.getCurrentController().getOwner()
own.scaling = [sx, sy, sz]

sx, sy, and sz is a float number to set the scale of the object to
for your second question you will have to use constraints and a soft body. I will see if I can make an example later

hi,
thanks for letting me know about scaling function, it works as charm :slight_smile:

as for second question - I just want to specify one thing - that ball is already doing what I want. I attached it that to S key, so when I hold it, ball is moving like pendulum. Because in my python script there are equations and I am setting ball location according to them. So I just need to add that string/thread like thing to ball, because it looks kind of stupid without it :smiley: I am not sure if I need soft body to do it. I know I can animate pendulum with soft body as well, but I want it to move according to my python script - do I still have to use soft body for that string/thread, or only constrains will do?

I used same procedure in “classic” blender to render animation and I did this string/thread thing using constrains (TrackTo), but it is not working in BGE (I have keyframes and ball + string/thread is moving together, but when I start game, string/thread is halted). I am not sure if I have to define constrain other way in BGE or what

I’m confused on what you are doing for the pendulum right now. can you post an example?

basicaly I am using runge-kutte to solve differential equations that defines pendulum movement. I took results from equations and I animate ball according to them

here is script:


if S.isPositive():
 
if own.omega1>0.000002 or own.omega1<-0.000002:
  def f1(fi, omega):
   return own.omega
  def f2(fi, omega):
   return -own.b*own.omega/own.m*own.l-math.sin(own.fi)*own.g/own.l
  k11=f1(own.fi,own.omega)
  k12=f2(own.fi,own.omega)
  k21=f1(own.fi+own.h2*k11,own.omega+own.h2*k12);
  k22=f2(own.fi+own.h2*k11,own.omega+own.h2*k12);
  k31=f1(own.fi+own.h2*k21,own.omega+own.h2*k22);
  k32=f2(own.fi+own.h2*k21,own.omega+own.h2*k22);
  k41=f1(own.fi+own.h*k31,own.omega+own.h*k32);
  k42=f2(own.fi+own.h*k31,own.omega+own.h*k32);
  
  own.fi += own.h/6*(k11+2*k21+2*k31+k41)
  own.omega += own.h/6*(k12+2*k22+2*k32+k42)
  own.omega1=own.omega
  own.x=own.l*math.sin(own.fi)
  own.y=own.l*math.cos(own.fi)
  [x,y,z]=own.getPosition()
  own.setPosition([own.x, -own.y, z]) 
  

and all I want to do now is to “attach” some string/thread to ball - one end will do exactly what ball do and the other end will be fixed still - I managed to achieve this in Blender, but I have problem how to get it done in BGE

If its a pendulum will the string need to change shape/size? Other wise you can set it up so it follows the ball, even if it changes size you can use the scaling method. I will post an example after I get your reply (so I know what you’re doing)

yea I want string to change size - I put some lines in my script so I can change length of string (and other variables) interactively and I would like to get graphic interpretation as well. But i guess something like this

own.scaling = [sx, sy, sz]

will do it there as well. As for shape, I guess I dont need to be able to change it, it will be just “straight stick” following the ball. (with one end that wont be moving of course)

thank you for your help

Ok, so what you can do is create a plane, scale in down on the x axis so it is thin like a string, then move the 2 lower vertices up 1 unit (so it is only 1 unit along the y axis), add a track to actuator to it and set the object to the ball and then position the string so that the centre of it (thats the end that won’t move) is where it should be.

If the length of the string is one unit you can use the distance from the string to the ball as the scaling of it on the y axis. The x and z axis should have scaling of 1 unit.

A different way you can do it is by drawing a line, this is done in python and can have no texture applied to it:

from Rasterizer import drawLine

start = [0,0,0] # the non-moving part of the string
end  = ball.getPosition() # the moving part
colour = [0.5,0.5,0.5] # the colour of the string in RGB format

drawLine(start,end,colour) # draw the actual line, has to be called every frame

I uploaded an example of the scaling method, click to move the ball

Attachments

string.blend (115 KB)

hi thx for example, i will try to get it according your procedure
can I use similar style when I want to have string in 3d? (i extrude circles so its look like string)

EDIT: well i did it primitively but it works in 3d now… I just joined cricles with plane :smiley: I guess there may be better solution but as long as this work… :slight_smile: thank you for help