Skip to main content
GameDev.net gamedev.net
🔒 Locked

Blender Python problem!

Started by PegasusBW Oct 2, 2009 at 11:10 PM 1 replies 1.3k views
Original Post
PegasusBW
PegasusBW
Hey! I am trying to get the location of my paddle object using the object.getLocation() command. Now, I print out the location onto the console every time the ball hits the paddle (this is just a test). The problem is, I always get the same location regardless of whether or not I move the paddle. here is the code:

import GameLogic
import Blender

paddle = Blender.Object.Get ('Paddle')
ball = Blender.Object.Get('Ball')

cont = GameLogic.getCurrentController()
me = cont.getOwner()

bounce = cont.getSensor("touchPaddle?")
g1 = cont.getActuator("BounceOffThePaddle")

if(bounce.isPositive()):
		print paddle.loc[0]

Am I using this function in the wrong way, or is there another way to print out the "current" location of the paddle? Thanks.
Zahlman
Zahlman
1) You say you're trying to use the .getLocation() method (not "command"; it is actually almost never correct to use the term "command" when talking about modern programming languages!), but it doesn't appear in your source code (instead you read the 'loc' of the paddle).

2) Are you sure that [0] is the part of the location you're interested in? I assume 'loc' is a tuple of 2 values, for an X coordinate and a Y coordinate. If you move the paddle vertically (i.e. change the Y coordinate), and display the X coordinate, then of course you aren't going to see changes.
PegasusBW
PegasusBW
.getLocation() returns a tuple and loc holds this's tuple values (xyz). loc[0] gives the x value. And thats what I was printing. However, I did find a function, while waiting for a reply, to print the changed value. But now I have another question.

import GameLogicimport Blenderpaddle = Blender.Object.Get ('Paddle')ball = Blender.Object.Get('Ball')cont = GameLogic.getCurrentController()me = cont.getOwner()bounce = cont.getSensor("touchPaddle?")g1 = cont.getActuator("BounceOffThePaddle")if(bounce.isPositive()):                pos = paddle.getLocation()		print pos.loc[0]


me.getPosition() prints the current, changed value to the console. Thing is,
me(cont.getOwner) can only own the controller for one object, which holds the script(namely, the ball). Is there a way to access another object's coordinates, within the same script, and without using getLocation(), or "loc" for that matter (because they only give the initial position, NOT the current position). Is there a way to do that, or no?

Edit: I moved the paddle only in the X direction, I am sure of it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.