one dimensional constraints

Game Engine, Players & Web Plug-in, Virtual Reality, support for other engines

Moderators: jesterKing, stiv

d52477001
Posts: 4
Joined: Thu Oct 24, 2002 6:52 pm

one dimensional constraints

Postby d52477001 » Thu Oct 24, 2002 7:11 pm

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

d0pamine
Posts: 30
Joined: Wed Oct 16, 2002 9:47 pm

setting only the x and z positions

Postby d0pamine » Thu Oct 24, 2002 8:22 pm

One way is to use python:

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

or something like that ...

Saluk
Posts: 166
Joined: Wed Oct 16, 2002 6:52 am

Postby Saluk » Fri Oct 25, 2002 7:26 am

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.

d0pamine
Posts: 30
Joined: Wed Oct 16, 2002 9:47 pm

duhh

Postby d0pamine » Fri Oct 25, 2002 1:51 pm

thanks!

d52477001
Posts: 4
Joined: Thu Oct 24, 2002 6:52 pm

Postby d52477001 » Fri Oct 25, 2002 2:11 pm

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

Saluk
Posts: 166
Joined: Wed Oct 16, 2002 6:52 am

Postby Saluk » Fri Oct 25, 2002 7:17 pm

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:)

d52477001
Posts: 4
Joined: Thu Oct 24, 2002 6:52 pm

Postby d52477001 » Sat Oct 26, 2002 2:21 pm

works perfectly thanks!

d52477001
"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones."

"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former."

–Albert Einstein


Return to “Interactive 3d”

Who is online

Users browsing this forum: No registered users and 0 guests