??? 'kx_gameobject' ?????

So i’m new to BGE scripting and i’m going through the documentation [ https://docs.blender.org/api/blender_python_api_current/contents.html ] like i would if i was using “Python 3.6” and focusing on the ‘Game Engine Modules’ section i’m trying to write a script because i know it’s better then logic bricks. But the problem i am having is that for the life of me i can’t understand how to use the ‘KX_GAMEOBJECT’ class [ https://docs.blender.org/api/blender_python_api_current/bge.types.KX_GameObject.html#bge.types.KX_GameObject ]
and after getting help on this forum on how to make my player go up by 1 blender unit, i now want to make the script put the player into dynamic physics. But i don’t just want that simple fix, i need help understanding how to use the ‘KX_GAMEOBJECT’ class so i can later figure it out on my own instead of coming to the forum for every little line of code. I know this is a very broad question to ask, but i’m hoping someone can recall the days when they were a newbie like me just learning to code :smiley:

Any Help Is Greatly Appreciated. I Thank You In Advance

you don’t really use kx game object. what that is, is the object itself. If you want to do something with it, just call its functions, like obj.applyMovement()

Thanks Nicholas_A, that simplify’s the thinking process for me now, one thing i notice i was doing wrong is that for example i would type ‘applyMovement’ in the script instead of ‘obj.applyMovement’ so it was not linking to the player. And thank you monster i think that guide will be very useful. so now that problem is almost solved (my understanding will increase as i put this into testing), basing this off of what you guys just taught me and from the documentation [ https://docs.blender.org/api/blender_python_api_current/bpy.types.GameObjectSettings.html?highlight=gameobjectsettings#bpy.types.GameObjectSettings.physics_type ] i would think that i could make a script like

import bge
cont = bge.logic.getCurrentController()
owner = cont.owner
owner.physics_type[‘DYNAMIC’]
and it would change the physics type of the object, but it doesn’t because if it hit play and then exit and look at the console it says something like ‘KX_GameObject has no attribute physics_type’, so now my question is, If ‘import bge’ calls the ‘KX_GameObject’ then what calls the ‘KX_GameObjectSettings’ ?

There is no “KX_GameObjectSettings”. Also importing “bge” does not import the KX_GameObjects, its not a direct link…

Rather, when you use the bge API (bge.logic.<method> or any other module), the functions might return an object of type “KX_GameObject”. The documentation simply list all the methods you can call on such objects.

Also, if you want to call “applyMovement”, you can use two ways:


import bge

# the one you should use
owner.applyMovement((.1, 0, 0))

# works the same way, but its silly
bge.types.KX_GameObject.applyMovement(owner, (.1, 0, 0))

You can see the list of available methods on game objects there:
https://docs.blender.org/api/blender_python_api_current/bge.types.KX_GameObject.html#bge.types.KX_GameObject.enableRigidBody

Also, the link you sent about KX_GameObjectSettings is from the “bpy.types” module. You should never use bpy when writing game logic. BPY is like the Blender Editor API, when the BGE module and submodules are for the actual BGE.

If you use BPY, then when eventually exporting your game the calls won’t work.

You can’t change the physics in-game. But you can change the parent-relationship (e.g. parent the visible object to an invisible object with physics).

ok Thanks, now i have a more off topic question. So some times i see people make scripts that have variables like wind = 1, gravity = 2, speed = 44 (random numbers) like when making a script for flying a plane. I am currently working on a boat game how would i get realistic boat movements out of it? Reqesting Answers (1) is it better to use scripting or animation, (2) how would i making with scripting, (3) is there any other way (other then scripting or animation) that i could/should do it with (4) whatever else you say

Think about it: it is a game - it is for entertainment. You do not need to simulate a real boat. It just needs to be plausible.

Therefore you are free to use whatever you want.

The animations can look really realistic. But due to their static behaviors they expect specific environment to remain plausible. There are quite a lot of cool tricks to make it more dynamic (e.g. playing two or more animations at the same time). Nevertheless it is a good idea to add some programmatic behavior.

These settings you are referring to are typically used to create different setups but using the same behavior. This flexibility allows you to create different boats with the same basic behavior but slightly different parameters. The benefit is … you do not need to build the boat logic multiple times. You reuse what you have and adjust the parameters. Be aware you buy this flexibility by spending more effort in the logic.

I know his is just a very generic answer. But there is no “right” answer. You need to pick the solution where you think it fits most in your specific situation. It might be you discover other solutions later because you build up experience on the topic. That is normal and does not mean your fist solution is incorrect.

Okay thanks so much guys, big help from you and nicholas