Python Question

Ok so I have a python question.

I set up a script to make the character run, walk, and jump. Now what I want is to set it up so that if he is running (up arrow) then when you jump, if you let go of the up arrow in air he will continue moving forward at the same speed until he hits the ground. So basicly I want him to retain the speed at which he was moving on the ground, whenever he is not touching the ground.

any ideas?

here is the script:

import GameLogic as gl
cont = gl.getCurrentController()
own = cont.getOwner()
up = cont.getSensor("up")
right = cont.getSensor("right")
left = cont.getSensor("left")
motion = cont.getActuator("motion")
walk = cont.getSensor("shift")
space = cont.getSensor("space")
touch = cont.getSensor("touch")
ray = cont.getSensor("forward_ray") and cont.getSensor("forward_ray1")
speed = 0.01
jumpspeed = 12
rotspeed = 0.04
move = 0
jump = 0
rotate = 0
if space.isPositive() and touch.isPositive(): jump = jumpspeed
if walk.isPositive():speed = 0.06
else: speed = 0.20
if ray.isPositive():speed = 0.01
if up.isPositive():move = speed

if right.isPositive():rotate = -rotspeed

if left.isPositive():rotate = rotspeed
gl.addActiveActuator(motion, 1)

is anyone going to help?

Doesn’t the physics engine already do this by default? I mean, assuming no other forces act upon your object, and general movement dampening is set to 0, your character should keep moving forward with the last walking/running speed.

A more specific explanation would certainly help.

Also, a simple .blend of your current setup would make things easier to test.

The code you’re using here is deprecated, please refer to the 2.49 docs:

Ok, let me clearify. Right now when you press up arrow the character moves forward and when you don’t press any keys he stays still. What I want is to make it so that if your pressing the up arrow and then you jump you no longer controll his forward speed untio he hits the ground. So basicly I don’t want you to be able to stop and go while flying through th air. Does that help?

also, i’m not sure why you think it is deprecated…

Yes, that helps:

You need to use a sensor that detects when the player is “on ground”. If that sensor is positive (if you’re on ground) execute all the control code. Else: don’t.

Also, you should use linear velocity for movement.

also, i’m not sure why you think it is deprecated…
Because it’s stated in the docs.

cont.getOwner() # Deprecated
cont.owner # Not Deprecated

sensor.isPositive() # Deprecated
sensor.positive # Not Deprecated

There are others, of course, but you can look those up yourself.

Try to avoid using deprecated functions, because those will be removed in 2.5 (afaik).

Ok, I still cant get this to work like I said. Here is a .blend for you to check out. All I ask is that you please delete this when you are done looking at it being that the game is not done yet and I don’t want any chance of it getting out to the public.

Oh yes, I tryed replacing “cont.getOwner()” with “cont.owner” and it didn’t work…

Try using a sensor to detect if the player is “on ground” and adjusts a bool property.
onGround = True
If the character is not “on ground” adjust the property to false.
onGround = False
Then in the script use up.isPositive() and onGround == True

  • Where is the download link?
  • Please don’t post your entire game project. Make a very, very simple .blend that uses only the movement script, using a single plane as the ground, and the default cube as the player. That way it’s easier for me to help you, and you don’t have to worry about anyone doing anything with your little game.

Oh yes, I tryed replacing “cont.getOwner()” with “cont.owner” and it didn’t work…
Are you using 2.49? If not, than that’s why.

If at all possible, switch to the new version of blender (2.49) and use the new syntax.

oh, yes… the new version of blender. I’m using blender on Ubuntu and they havn’t released a .deb install file for ubuntu yet. I’ll post motion demonstration blend up shortly. Thanks for you help.

ok here is a blend like you asked. I want him to still be able to rotate in air btw

hey social, could you take a look at this blend?

you can find the .deb for ubuntu on the blender download page, below linux x86

You didn’t follow instructions. The .blend carried unnecessary textures/bricks; you were supposed to strip those out.

I’ll help you out regardless this time, but please, for future reference, do your best to strip out all the unnecessary components (you might actually find a solution yourself that way).

Also, you can attach .blends directly to your post, just the way I’m doing here.

PS: You don’t have to wait until 2.49 shows up in the ubuntu repositories, and you shouldn’t, because they’ll always be a version behind. Download the compressed package for linux x86, extract to desktop (or wherever you want to keep it) and run blender. It should work fine, without the need to actually install anything.


movment_scmod.blend (703 KB)