Tracking the relative position of an object

Added by john smith 3 months ago

Hello,

I'm creating a simple breakout (Brick Breaker) game for a school project and I'm trying to use the CMUcam5 to track an object and move the game paddle accordingly to the relative position of the object. As of right now, I have the paddle moving either left or right, if the object appears to be either left or right to the center of the camera. But I'm trying to improve the tracking and have the paddle move simultaneously to the relative position of the object. My code for the movement of the paddle is below:

def paddleUpdate(self):
count = pixy_get_blocks(100, blocks)
if count > 0:
for index in range (0, count):
if blocks[index].x<150:
if self.paddle[-1][0].x < 790:
for paddle in self.paddle:
paddle[0].x += 10
elif blocks[index].x>150:
if self.paddle[0][0].x > 0:
for paddle in self.paddle:
paddle[0].x -= 10

Replies (1)

RE: Tracking the relative position of an object - Added by Jesse French 3 months ago

Hi John,

seems like you could achieve the simultaneous paddle movement by doing some simple data smoothing on the X value of the current block, and setting your paddle position equal to the smoothed value.

Hope this helps,
Jesse

(1-1/1)