Page 1 of 1

one dimensional constraints

Posted: Thu Oct 24, 2002 7:11 pm
by d52477001
hi guys,

i have a problem with a tennis game that i am making. Basically i want the racket to follow the ball in the up-down direction but not in any of the other diresctions. how can i do this?

thanks

d52477001

setting only the x and z positions

Posted: Thu Oct 24, 2002 8:22 pm
by d0pamine
One way is to use python:

ballpos = ball.getPosition()
racquetpos = racquet.getPosition()
racquet.setPosition([ballpos[0],racquetpos[1],ballpos[2]])

or something like that ...

Posted: Fri Oct 25, 2002 7:26 am
by Saluk
Actually, this:
racquet.setPosition([ballpos[0],racquetpos[1],ballpos[2]])

Should be this:
racquet.setPosition([racquetpos[0],racquetpos[1],ballpos[2]])

Otherise it would follow the ball on TWO axis.

duhh

Posted: Fri Oct 25, 2002 1:51 pm
by d0pamine
thanks!

Posted: Fri Oct 25, 2002 2:11 pm
by d52477001
hmm i'm not really comfortable with python yet... any way to do it with logic bricks? if not then i'll give it a try.

is that all that there is needed? no header or anything? and then how do i get it to run in game?

thanks.

d52477001

Posted: Fri Oct 25, 2002 7:17 pm
by Saluk

Code: Select all

c = GameLogic.getCurrentController()
raquet = c.getOwner()
ball = c.getActuators()[0].getOwner()

ballpos = ball.getPosition()
raquetpos = raquet.getPosition()
raquet.setPosition([raquetpos[0],raquetpos[1],ballpos[2]]) 
Steps to put in game:
  1. Copy the code snippet
  2. Paste into text editor
  3. Save the file as "copyx"
  4. Go to the text editor. (In each blender window's header there is a button all the way on the left that lets you change the window type. The text editor looks like a white squesre with some text. You can also make a new blender window by moving the mouse to the division between the two windows and right clicking.)
  5. In the middle of the text editor's header is a white dot file selector. Grab this and select "open new"
  6. Find your saved text file, select it, and hit enter
  7. In the raquet's game logic, add an always sensor, connected to a PYTHON controller
  8. Enter "copyx" into the text box on the python controller
  9. Shift select the ball (That is, select both the racqet and the ball at the same time)
  10. Make both objects logic bricks appear (at the top of the logic editor, click on all the buttons that say "sel")
    Connect the python controller to any of the actuators on the ball. If the ball doesn't have any actuators, just add a motion actuator
  11. Test it, and if it works come back and make sure I had everything straight
  12. From now on, try to ask "Usage" questions at elysiun. These forums are meant for blender development only:)

Posted: Sat Oct 26, 2002 2:21 pm
by d52477001
works perfectly thanks!

d52477001