Pong bat a.i issues

This forum is currently in read-only mode.
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • Hopefully I got the right sub forum as this is more to do with the actual python logic code and/or controlling event sheet.

    While working with construct i created a variation of the 8dir behavior to allow an event sheet to control it all is working but the a.i is not perfect, at this time it is not correctly going to the last location the ball goes off screen, then resuming its normal behavior once it has deflected the ball, rather maintaining its normal behavior, in addition a minor flaw i suspect is that the movement is not taking acceleration into account.

    I have two bats, one being the player on the left of the layout using a an 8 direction behavior for movement, the other being a a.i bat using a modded 8 direction movement that allows me to send input via the event sheet(so both are using the same movement setup, just ones using a pretend keyboard).

    They have a max speed of 500, a acceleration of 600, a deceleration of 600.

    The ball uses the stand ball behavior with a speed of 300 and a max speed of 1000.

    The event sheet responsible for the a.i has the following(python script included)

    [quote:1kh8siwa]LIB - On function "AIStop" AIBat : Move stop

    LIB - On function "AIUp" AIBat : Move Up

    LIB - On function "AIDown" AIBat : Move Down

    #This script controls the core logic
    #For the Bat AI
    import random;
    def AI_AdjustToAngle():
    	global AI_AdjustRate;
    	global AI_BallAngle;
    	if ((AI_BallAngle > 90) and (AI_BallAngle < 180)):
    		return AI_AdjustRate;
    		return -AI_AdjustRate;
    	return AI_AdjustRate;
    #Track last area ball whent out of.
    def SetBallParkArea(val):
    	global AI_LastOutY;
    #On/Off switch for player 2 a.i
    def EnableAI(arg1):
    #Give a bit of randomness to the a.i reaction distance.
    def AI_GetRandomiseMidFeild():
    	#return random.randint(0, 5);
    	return 0;
    #Skill related, tells our a.i how much
    #to compensate for the ball.
    #Take into account the balls angle here
    def AI_GetCompensation():
    	global AI_BallAngle;
    	global AI_NoCompensate;
    	global AI_MaxRandom;
    	global AI_MinRandom;
    	if (AI_NoCompensate == 1):
    		return 0;
    	if ((AI_BallAngle > 90) and (AI_BallAngle < 180)):
    		return random.randint(AI_MinRandom, AI_MaxRandom);
    		return -random.randint(AI_MinRandom, AI_MaxRandom);
    	return random.randint(AI_MinRandom, AI_MaxRandom);
    #A.I think loop
    def AI_Think():
    	if (AI_Enable == 0):
    	global AI_BallAngle;
    	global AI_TargetY;
    	global AI_NoCompensate;
    	global AI_ReactionDistance;
    	global AI_LastOutY;
    	#Its on the players side of the playing feild, wait for it to come to ours.
    	if (Ball.X < (320-AI_GetRandomiseMidFeild())):
    		LIB.Call("AIStop", 0);
    	#For now disable A.I compensation
    	#Always goto the last spot the ball whent off screen at for the a.i bat.
    	if (AI_LastOutY != 0):
    	AI_TargetY += AI_GetCompensation();
    	#Adjust in relation to ball angle.
    	#AI_TargetY += AI_AdjustToAngle()+AI_GetCompensation();
    	#Adjust our position to line up with the ball.
    	if (abs(AI_TargetY-AIBat.Y) > AI_ReactionDistance):
    		if (AI_TargetY > AIBat.Y):
    			LIB.Call("AIStop", 0);
    			LIB.Call("AIDown", 0);
    		if (AI_TargetY < AIBat.Y):
    			LIB.Call("AIStop", 0);
    			LIB.Call("AIUp", 0);
    	if (abs(Ball.Y-AIBat.Y) < AI_ReactionDistance):
    		LIB.Call("AIStop", 0);
    [b]Ball - Is outside layout[/b] System : run script "SetBallParkArea("+str(Ball.Y)+");"
    [b]abs(AIBat.X-Ball.X) greater than 8
    On collision between Ball and AIBat[/b]  System : run script "SetBallParkArea(0);"
    [b]Always(every tick)[/b] System : run script "AI_Think();"
    Any help or advise would go a long way.
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)