I have the following little script that adds an object (bullet) when the mouse left button is pressed.
The icosphere is the bullet.
The cube is the gun.
It’s working well, the bullet is sent (see image below, yellow direction).
* Can’t set linearVelocity if first added object is still alive?
If I press left click before the first bullet has disappeared, the next added object (bullet) doesn’t have his linear velocity set (see image below, in red).
* Script played twice?
Also, the script is played twice even if I use the Tap option on the Mouse sensor.
Here is the script :
import GameLogic as g scene = g.getCurrentScene() objList = scene.objects cont = g.getCurrentController() own = cont.owner # sensor mouse_attack = cont.sensors["mouse_attack"] shoot_obj = objList.get("OBGun") bullet_obj = "Bullet1" bullet_life = 20 bullet_speed = 10 # Add Bullet at Gun position add_obj = scene.addObject(bullet_obj, shoot_obj, bullet_life) obj = scene.objects.get(add_obj.name, "OBBullet_1") obj.setLinearVelocity([0.0, bullet_speed, 0.0], True) print "done"
and an example .blend
If somebody can help?
example.blend (137 KB)