Posted: Thu Oct 24, 2002 6:11 pm
Joined: 24 Oct 2002
Posts: 4
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
Posted: Thu Oct 24, 2002 7:22 pm
Joined: 16 Oct 2002
Posts: 29
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 6:26 am
Joined: 16 Oct 2002
Posts: 166
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.
Posted: Fri Oct 25, 2002 12:51 pm
Joined: 16 Oct 2002
Posts: 29
Posted: Fri Oct 25, 2002 1:11 pm
Joined: 24 Oct 2002
Posts: 4
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 6:17 pm
Joined: 16 Oct 2002
Posts: 166
| Code: |
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:
- Copy the code snippet
- Paste into text editor
- Save the file as "copyx"
- 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.)
- In the middle of the text editor's header is a white dot file selector. Grab this and select "open new"
- Find your saved text file, select it, and hit enter
- In the raquet's game logic, add an always sensor, connected to a PYTHON controller
- Enter "copyx" into the text box on the python controller
- Shift select the ball (That is, select both the racqet and the ball at the same time)
- 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
- Test it, and if it works come back and make sure I had everything straight
- From now on, try to ask "Usage" questions at elysiun. These forums are meant for blender development only:)
Posted: Sat Oct 26, 2002 1:21 pm
Joined: 24 Oct 2002
Posts: 4
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