0
$\begingroup$

I'm making a mini golf game and right now I just have a cube that lurches forward to collide with the ball, there's not variability in the shot power. I'm looking for a way to move the ball forward without using the block, instead based on the length of the keypress to simulate variable power (a quick press = light tap on the ball...long press = hard hit) I know this is possible because I've seen other blender games that do such a thing. Any ideas?

Here's my .blend file if you wanna have a look https://drive.google.com/file/d/0BxB2pKMjGzzqUk9jLXFJWDRGVWc/view?usp=sharing

$\endgroup$
0

1 Answer 1

1
$\begingroup$

Ok, I don't have much time today, so I will just provide a few hints and try to guide you in the right direction. I think there are basically three ways of approaching your problem.

  1. The pythonic way. You can use a python script on your golfball which uses the applyImpulse method of the game object. This is basically what you asked for. You need to start some timer once a key is pressed and apply an impulse to your golf ball one the key is released. Bam!
  2. The physical simulation of a golf club. You could use two objects connected by a hinge which serve as a simplified golf club. You can find a nice introduction on John Hamiltons Introduction to rigid body joints
  3. The non pythonic way. The "Action" actuator allows to apply the value of an IPO curve as a force to an object. This basically lets us create arbitrary nonlinear force vs. time curves which can be applied to a certain axis. Here is an example using a force applied to the object in global z-Axis. enter image description here

Most probably you will find an elegant solution by combining these methods. I know this is not a ready to use example. But hey - I showed you the door. You're the one that has to walk through it. ;]

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .