Scripting help: linear velocity/property variables

Hello everyone,

As most on this forum, I’m in process of making my own game and require some assistance form those more experienced than myself. As a quick synopsis, I’m making a sort of free-roam car game. At the moment it’s more for myself and own pleasure in making my own little world and models and being able to cruse around it, but I may eventually add in a sort of adventure storyline to it.

The nature of the help I need has to do with the programming aspect and editing scripts, which I have very little to no experience in. Though this may almost sound snobbish, I honestly don’t have the time on my hands to learn programming and scripting. So, I need some advice on exactly how to do a couple probably simple functions.

Here’s the blend file packed up, so you can tell what I’m going to attempt explain in the following:

http://www.mediafire.com/?bqt70qpcm2x2p

I tried putting in a linear velocity script, but I’m not sure if it’s the right one or if I’ve even set it up right. What I want it to do is simply take the speed of the car (OBLotus) and assign this numerical value to a property called Speed, on the Lotus.

from GameLogic import*
  scene = getCurrentScene()
  object_list = scene.objects
   
  car = object_list["OBLotus"]
  car["Speed"] = car.getLinearVelocity()[1]+1

Any thoughts of what I’m doing wrong?

For the next part, I want to be able to add in a variable to a couple places on a pre-existing script. In a non-technical way, I want the wheels to not go to their maximum rotations immediately when the key is pressed; that is, if the key is pressed and held, then after say half a second the wheels would get to maximum turn. I’ve set up with logic bricks a property to define the steering, having values from -1 to 0 for turning left and from 0 to 1 for turning right. The following script is what I currently have, as the original script for the part with steering.

##################################################  Steering 
   
  def Steering( vehicleID, controller):
   
              # set turn amount
              turn = 0.6
              
   
              # get steering sensors
              steerLeft = controller.sensors["Left"]                        # sensor named "Left"
              steerRight = controller.sensors["Right"]            # sensor named "Right"
                          
              # turn left            
              if steerLeft.positive == True:
                          
                          turn = turn
              
              # turn right            
              elif steerRight.positive == True:
                          
                          turn = -turn
              
              # go straight            
              else:
                          turn = 0.0
                          
              # steer with front tires only
              vehicleID.setSteeringValue(turn,0)
              vehicleID.setSteeringValue(turn,1)
   
   
  ###############################################

This is what is already in the script for the turning part. I’m guessing what I want will look something along the lines of the following (without the actual proper programming language, that is):

##################################################  Steering 
   
  def Steering( vehicleID, controller):
   
  Get scene objects
  Get property “propertySteering”
   
              # set turn amount
              turn = 0.6*[“propertySteering”]
              
   
              # get steering sensors #well, they're not sensors, as turning should be based only on the number product above
              steerLeft = if “turn” >0
              steerRight =if "turn" <0
                          
              # turn left            
              if steerLeft.positive == True:
                          
                          turn = turn
              
              # turn right            
              elif steerRight.positive == True:
                          
                          turn = -turn
              
              # go straight            
              Turn product = 0
                          
              # steer with front tires only
              vehicleID.setSteeringValue(turn,0)
              vehicleID.setSteeringValue(turn,1)

Can you tell more or less tell what I’m trying to do here? (and how to actually properly set it up?) :wink:

On a side note: is there an easy way to copy the property value of one object to a property value of another (through logic bricks, script or otherwise)?

Thanks a million again for any and all help!

before I even try going through this, try looking in the blender console for any errors and fix them.

For the linear velocity part, I went through and tried it on a different file, and I’ve come to the conclusion that the script works (except for the +1 part) so long as the object it’s getting the speed for doesn’t hold the vehicle wrapper script or is parented to the vehicle wrapper object, which it won’t work for the object I need it for. Has anyone had this problem before, with more than one script on an object at once? I tried combining it with the vehicle constraint, but couldn’t get it to work…

Okay, sad as it sounds, I’ve got it sort of working; as in, I’ve parented an object to it that was a rigid body object to it, which allows it to be senses by the python. But I’ve come to another problem that it calculates only speed along the global y axis, so if I’m cruising down at max speed going west, it’ll think I’m not moving at all, as I’m only going along the global x axis. How would I add the local part in?