mathew653's Recent Forum Activity

  • 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;
    
    AI_Enable=1;
    
    AI_LastOutY=0;
    AI_TargetY=Ball.Y;
    AI_BallAngle=int(Ball.Angle);
    
    AI_MaxRandom=5;
    AI_MinRandom=0;
    #AI_ReactionDistance=16;
    AI_ReactionDistance=12;
    AI_NoCompensate=0;
    AI_AdjustRate=2;
    
    def AI_AdjustToAngle():
    	global AI_AdjustRate;
    	global AI_BallAngle;
    	if ((AI_BallAngle > 90) and (AI_BallAngle < 180)):
    		return AI_AdjustRate;
    	else:
    		return -AI_AdjustRate;
    	return AI_AdjustRate;
    
    #Track last area ball whent out of.
    def SetBallParkArea(val):
    	global AI_LastOutY;
    	AI_LastOutY=val;
    
    #On/Off switch for player 2 a.i
    def EnableAI(arg1):
    	AI_Enable=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);
    	else:
    		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):
    		return;
    	
    	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);
    		return;
    	
    	AI_TargetY=Ball.Y;
    	AI_BallAngle=int(Ball.Angle);
    	#For now disable A.I compensation
    	AI_NoCompensate=0;
    	
    	#Always goto the last spot the ball whent off screen at for the a.i bat.
    	if (AI_LastOutY != 0):
    		AI_TargetY=AI_LastOutY;
    		AI_NoCompensate=1;
    
    	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);
    [/code:1kh8siwa]
    [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.
  • Thanks again for the help provided so far, it has been a blessing.

    I have another question, currently i plan to do ledge climbing like so

    Create an invisible sprite that when touched disables the players normal jump replacing it with an animation what is not affected by gravity, where the player jumps off the ground and climbs up a ledge.

    Now on construct, collision is handled per pixel but the physics engine is box2D(as far as i understand), so if i set the player platforms gravity to -1 will this make it static for the course of the animation?

    Another concern, am i making this too complicated? Is there a simpler way and/or a plugin that will do the dirty work for me?

  • Thank you for your response so far, I have found the information very helpful, Still trying to get the camera to default its zoom at 200%, but you have put me on the right track with other elements.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hello, I have adopted construct classic for a game development project with a friend, but there are a few things I have encountered with it what I am not able to implement a entirely clear fix for.

    I got into this project with some experience of coding already, having used c, c++ and other programming languages so far for the sake of speed I have avoided trying to write any native plugins, but I have gotten my self caught up on a few snags:

    The first is somewhat of simple issue but an approach I am not entirely certain about the approach for :

    I have been asked to implement a camera with zoom support:

    I have managed to set the camera zoom via "system - Set Zoom"

    Now this works, as long as I enable unbounded scrolling on the layout, the trouble occurs when I enable it

    The camera cuts off the bottom of the layout and part of its left side.

    Now i can manually make the camera track the player via an event sheet using system - scroll to x/y and using the players location.

    But how is the best way to make this type of camera keep within the layout bounds this needs to work for if a scene needs a zoom out and zoom in effect also.

    The second is animation related, from what I can see I cannot ask a sprite how quickly it is moving, for example how do I make a sprite do a skid animation when they have been running for a while(built up momentum)

    The third is somewhat of a weird situation that has occurred, seemingly related to screen transitions and offscreen layout switches

    The bug occurs in the non test setup when the screen has a fade transition and the following event sheet is setup for the layout:

    player is outside layout:
    (inverted)if Y less than 0 
    (inverted)if Y greater than LayoutHeight
    (inverted)if X greater than LayoutWidth
    if X less than 0
    
    with the action
    Goto layout # with transition "fade" lasting 10ms
    [/code:2l3rdk87]
    
    That is from the test where it works, on the one where it is bugged the fade time is different i currently do not have the project for the exact number but if needed i can obtain it.
mathew653's avatar

mathew653

Member since 14 Apr, 2014

None one is following mathew653 yet!

Trophy Case

  • 10-Year Club
  • Email Verified

Progress

11/44
How to earn trophies