Dynamic terrain loading for many vehicles

here is a blend with a python script that blueprintrandom made.
State_machine_added_melee3c.blend (1002.7 KB)

to play the game prototype.press w,a,d to move when you get close to one of the cars then press 1 to control that car.how would i make a dynamic terrain loading script that can be used on each car in the scene?

Why on ethe car? Wouldn’t it make more sense to create terrain around the camera?

1 Like

each car would have a camera.i would like to create terrain around each of those camera’s.

1 Like

here is the python code I adjusted for dynamic terrain loading with many vehicles that does not work.

import bge
from CeilManager import CeilManager
cont = bge.logic.getCurrentController()
own = cont.owner





#this applies the basic movementForces WALK RUN AND CRAWL

def ApplyMovement(speed, xFriction,yFriction):
   

    L = own.localLinearVelocity.copy()
    L.z = 0
    if not "ceil_manager" in own:
            own["ceil_manager"] = CeilManager(own)
        own["ceil_manager"].ApplyMovement()
        own["pos"] = str([round(v) for v in own.worldPosition])
        
    if L.magnitude>speed:
 

        own.localLinearVelocity.x*= .95
        own.localLinearVelocity.y*= .95
        
    if 'LEFT_STRAFE' not in own['Move'] and 'RIGHT_STRAFE' not in own['Move']:
        own.localLinearVelocity.y*= 1 - yFriction
        
    if 'Forward' not in own['Move'] and 'Back' not in own['Move']:
        own.localLinearVelocity.x*=1 - xFriction    
    if 'Forward' in own['Move']:
        if own.worldLinearVelocity.x<speed:
            own.applyForce(10*own.worldOrientation.col[0],0)
            
    elif 'Back' in own['Move']:
        if own.worldLinearVelocity.x>-speed:
            own.applyForce(-10*own.worldOrientation.col[0],0)
        
    if 'Left' in own['Move']:
        own.applyRotation((0,0,.05),1)
    elif 'Right' in own['Move']:
        own.applyRotation((0,0,-.05),1)



#decide what type of punch to use
def Punch(args):
    time = args[0]
    
    if 'Punch' not in own['Act']:
        if time>=15:
            own['ActState'][0] = [ 'SuperPunch', [15,time]]
        else:
            own['ActState'][0] = [ 'Jab', [15]]
    
    elif time<29:
        own['ActState'][0][1][0] +=1
        
        
        
        
def SuperPunch(args):
    Time = args[0]
    Strength = args[1]
    
    if Time>=1:
        own['ActState'][0][1][0] -=1
    else:
        own['ActState'].pop(0)
    if Time==7:
        end = own.worldPosition+own.worldOrientation.col[0]*4
        bge.render.drawLine(own.worldPosition,end,(1,1,1))
        ray = own.rayCast(end,own.worldPosition,0,"",0,0,0)
        if ray[0]:
            print('hit')
            ray[0].applyImpulse(ray[1], own.worldOrientation.col[0]*Strength)
            if 'Health' in ray[0]:
                ray[0]['Health']-=(Strength*2)+5
        own.color = [0,0,1,1]    

def Jab(args):
    Time = args[0]
    if Time>=1:
        own['ActState'][0][1][0] -=1
    else:
        own['ActState'].pop(0)
    if Time==7:
        end = own.worldPosition+own.worldOrientation.col[0]*2
        bge.render.drawLine(own.worldPosition,end,(0,1,0))
        ray = own.rayCast(end,own.worldPosition,0,"",0,0,0)
        if ray[0]:
            ray[0].applyImpulse(ray[1], own.worldOrientation.col[0]*1)
            if 'Health' in ray[0]:
                ray[0]['Health']-=5
        own.color = [1,1,1,1]

                
def VehicleCheck(args):
    Time = args[0]
    if Time>=1:
        own['ActState'][0][1][0] -=1
    else:
        own['ActState'].pop(0)
    if Time==7:
        end = own.worldPosition+own.worldOrientation.col[0]*2
        bge.render.drawLine(own.worldPosition,end,(0,1,0))
        ray = own.rayCast(end,own.worldPosition,0,"",0,0,0)
        if ray[0]:
            if 'Actor' in ray[0]:
                own.scene.objects['Controller']['Target']=ray[0]
        own.color = [1,1,1,1]    
                    
                  
 
 
                 
def Sprint(args):
    #print('called sprint')
    xFriction = .05
    yFriction = .25
    ApplyMovement(own['Speed']*4,xFriction,yFriction)
    #this is where we would call animate Actor basic movements 
    
    
    #this is where we do an exit condition
    #forgot to change the exit conditions in the states
    #after I swapped from sensors to a controller object
    
    #JUST DID JAB JAB JAB SUPER PUNCH
    if 'Sprint' not in own['Act']:
        print('pop')
        print(own['Act'])
        own['ActState'].pop(0)                 
        
    #feedback
    own.color = [1,1,0,1]
    #sprint is yellow
    #crawl is red
    #walk is green
    



def Crawl(args):
    #print('called crawl')
    xFriction = .25
    yFriction = .25
    ApplyMovement(own['Speed']*.1,xFriction,yFriction)
    #this is where we would call animate Actor basic movements 
    if 'Crawl' not in own['Act']:
        own['ActState'].pop(0)
    own.color = [1,0,0,1]    



#we can add a infinite number of states since they are called using a dict lookup cost is  - o(n)




commandString = {"Crawl":["Crawl","None"], "Sprint":['Sprint',"None"], "Punch":['Punch',[0]], "VehicleCheck":["VehicleCheck",[15]] }

functionDict = { "Crawl":Crawl , "Sprint":Sprint, "Punch":Punch, "Jab":Jab, "SuperPunch":SuperPunch, "VehicleCheck":VehicleCheck}




    




#this is what gets called each frame

def main():
    
    if 'init' not in own:
        own['init']=True
        own['Act']=[]
        own['Move']=[]
        
        
    
    
    #decrease idle Timer        
    if own['Run']>=1:
        own['Run']-=1
        

    if not 'ActState' in own:
        #proccess input if not in state
        xFriction = .95
        yFriction = .125
        if own['Act']==[]:
            #this should be named applyMovement instead of proccess input
            ApplyMovement(own['Speed'],xFriction,yFriction)
            own.color = [0,1,0,1]
            
            #this is where we would call animate Actor basic movements 
                
        else:
            print(own['Act'])
            ip=""
            for entry in own['Act']:
                ip+=entry
            if ip in commandString:    
                #this intializes a state    
                own['ActState'] = [ commandString[ip]    ]
                
          
                #print(commandString[ip]    )
                
                
                
    #this runs the state        
    elif len( own['ActState'] )>=1:
        #Run State
        own['Run']=120
        Data = own['ActState'][0]
        #print(Data)
        
        function = functionDict[ Data[0] ]
        function(Data[1])
        #example ActState = [ ['Jab', frame] ]
        
    else:
        #leave states and proccess input
        del own['ActState']
            
        
    own['Act']=[]
    own['Move']=[]

 

main()

i forgot i had the marcoit’s dynamic terrain loading script for vehicles.

Did you ever get it to work? Just curious.

i am using marcoit’s dynamic terrain loading script for many vehicles.

1 Like

Sweet. I was curious to see if anything became of it.

Where can I find marcoit’s dynamic terrain loading script?

Hey, that is mine bro…

I wrote that for Manic mac

1 Like

Then upload the script or blend file please :thinking:

Or is your internet still slow :smile: :wink:

try this link it does not have a vehicle but it does have dynamic terrain loading script in a blend.

1 Like

@Lostscience I think you are trying to reply to @IamKraZ & not me :wink:

really it is for both of you.

I didn’t ask for anything :face_with_raised_eyebrow:

But I did, lol. @RPaladin I had to ask, lol.

Thank you @Lostscience.

@BluePrintRandom You wrote that? dude… puff puff give give, lol.

@RPaladin I had to ask, lol.

Sorry if I insulted you :thinking:

It’s just your the 10th person to reply to me on accident.

Actually it shows you, but most people are just hitting the ‘Reply’ button at the bottom of the screen.
So please don’t get upset.
It’s just a reply :slight_smile:

There is a no-reply-post button at the bottom-middle.

ReplyButton.bmp (4.5 MB)

It’s right there, unless yours is a different.