ANOTHER QUESTION ON PAGE 3 :P Project LearnMorePython

Sonic14: Have you looked at the blender 2.58 python documentation? It tells all about objects’ properties and could probably answer many of your questions in one fell swoop :cool:

Thanks, Lakitu. I will have that open in a new tab :). Now I have a new question. For the vine swing, I figured the way I could do it was, whenever I touched the vine, it would play the animation, suspend the dynamics, parent itself to the vine, and when the animation was complete, remove parent, restore dynamics. My question is that, how would I use python to parent itself to whatever vine it touched? (Conisdering there were several vines.)

Always use print(dir())

You want something along the lines of


if vine_collision.positive:
    vine = vine_collision.hitObject
    own.parent = vine
    #this might actually be own.setParent() instead

Infininte, I can’t seem to get your code to work (I am using 2.57).

Also, new question, I changed the .applyMovement to .setLinearVelocity and whenever I walk off a ledge, I walk on air unless I let go of the buttons.

What exactly isn’t working?

You’re setting the Z velocity to 0 when you move, so he can’t fall. If you only change the Y velocity, then he will fall.

[dx,dy,dz] = obj.getLinearVelocity(True) # Get local linear velocity

# Do stuff to velocity
# ...
if walkButton.positive:    # key pressed
     dy = 5 # or whatever you're using
# ...

obj.setLinearVelocity([dx,dy,dz], True) # Set local linear velocity

As Lakitu says what’s not working? I used the same principle in my own game that is using 2.57.

It is possible your getting an Nonetype error, try the code again with print(vine_collision.hitObject)

One last thing it may be .hitObject()

@Infininte - You were right the first time, Infininte. It isn’t sensor.hitObject(); it’s a property - sensor.hitObject.

@Sonic - Infininte is correct that you might be getting an error. Are you using the console?

When I said it wasn’t working I didn’t mean I was getting any kind of error, I meant that whenever I jumped onto the vine, I still didn’t stick to it. Actually, now that I think about it, the dynamics didn’t suspend… I was using the same variable and actuator for this that I was using for the climb up ledge part of the script. Could that be a problem? Maybe I don’t have my properties set up right or something for it to be working either…

Okay, I just figured out that my dynamics aren’t being suspended when I pull myself up the ledge. Which mean that my dynamics aren’t being suspended at all at any time in the game. Everything looks right in the script. I am not getting an error in the console. And I am pretty sure that the dynamics were suspending before because I know I was having a problem with them being restored. Why else would my dynamics not suspend?

You could try using the own.suspendDynamics, and own.restoreDynamics options instead of the actuators. That might help.

if ledgedetect.positive:
obj.suspendDynamics()
cont.activate(pullup)
cont.activate(ppullup)

if obj[‘pullup’] == 40:
obj.restoreDynamics()

Problem? Whenever the property ‘pullup’ equals 40, it restores dynamics. But it remains forty only for an instant, then the dynamics become suspended again (I think, anyway). How would I prevent this?

Checking

if ledgedetect.positive and obj[‘pullup’] < 40:

should work.

EDIT: Once you restore dynamics (and when ledgedetect isn’t positive), don’t forget to reset the ‘pullup’ frame back to 0.

Hm, that didn’t seem to work. BUT I got enough of it working (just now) so that it can suspend and restore dynamics. But the problem I am having now is that, whenever I restore the dynamics, the physics cube pushes me down and off the object. I think the issue is is that whenever I restore dynamics, it still keeps the world velocity (??? maybe???). How would I fix THAT.

own.worldVelocity = [0.0, 0.0, 0.0]

Console says-

File “player.py”, line 117, in <module>
AttributeError: ‘KX_GameObject’ object has no attribute ‘worldVelocity’
Python script error - object ‘Cube.001’, controller ‘Python#CONTR#1’:
Traceback (most recent call last):

There is no worldVelocity property. You can, though, use the obj.setLinearVelocity() function, if I recall.

Sorry, I meant own.worldLinearVelocity = [0.0, 0.0, 0.0]