assisting a BGE Greenhorn

hopefully i can come up with something here ive been working on a game project as to give myself something to do as a new year resolution and all that…

basicly im not a coder… at all i can understand code but i cant produce it to a useable level and i came across something in my game project that seems it needs pythont o make it do what i want to how ever ide like to if i can use logic bricks …unless i can figure out the python for it

in short i have a skiball game with a moveable ball thrower everything in it so far i can do with logic bricks throwing the ball moving the “hand” side to side keeping score and all that how ever i wanted to impliment a vairable power’d thrower

i THOUGHT i could do that with bricks but it seems im unsure how to do this and python came to mind
i wanted to use W/S to adjust the power level a game property vairable then using space bar to fire the ball forwards local Y for the “hand” using the value in the power vairable as the linear velocity

i can see it in my mind how i wanted it to work but i cant code my way out of a notepad…

is what i want possable with logic bricks or would it be wise to learn python and do it with that?

would it be over complicating things to logic brick this if that’d be possable at all?

thanks for any / all the help


You can use logic bricks to assign values to properties, but as far as I know there isn’t away to control the speed of an object with a property without using Python.

Here’s a simple script you could use on the ball.

import bge

# get object and power
cont = bge.logic.getCurrentController()
ball = cont.owner
power = ball['power']

# set ball's velocity
ball.localLinearVelocity = [0, power, 0]

Continue to use W and S to adjust the ‘power’ property on the ball using logic bricks. Execute the script on the ball when the space bar is pressed.

see that seems silly simple… i dont get why python eludes me like that XD
would i beable to apply that to the thrower though since thats whats fireing the ball at the set velocity?

Sure, just make sure you get the power property from the correct object and replace <ballName> with the name of the ball object in the scene.

import bge

# get objects
cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
ball = scene.objects['&lt;ballName&gt;']
hand = cont.owner

# get power
power = ball['power']
# if 'power' is a property on the hand use "power = hand['power']" instead

# set ball's velocity
ball.localLinearVelocity = [0, power, 0]