Previous Thread  Next Thread

chat icon one dimensional constraints

d52477001

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
Reply with quote


d0pamine

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 ...
Reply with quote


Saluk

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.
Reply with quote


d0pamine

Posted: Fri Oct 25, 2002 12:51 pm
Joined: 16 Oct 2002
Posts: 29
thanks!
Reply with quote


d52477001

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
Reply with quote


Saluk

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:

  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:)
Reply with quote


d52477001

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
Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group