Assume that all the actuators and sensors are spelled the right way.
Can anyone find a mistake? Because neither the “add_bullet” actuator or the “recoil” actuator work.
have you imported bge.logic?
if you’re using 2.55 use “import GameLogic”, then change bge.logic to GameLogic to make it easier to use old scripts.
Next you’re using deprecated code. i used this tutorial a while ago. i’ll change it
#with the latest 2.5* BGE you must import GameLogic
import GameLogic
#sets the script controller as cont
cont = GameLogic.getCurrentController()
# gets the sensors, now uses cont.sensors[""], not getSensor(""). also uses .positive, not isPositive()
fire = cont.sensors["fire"].positive
# gets the actuators, now uses cont.atuators[""], not getActuator("")
add_bullet = cont.actuators["add_bullet"]
recoil = cont.actuators["play_recoil"]
# variables
isFiring = False
# events #
##########
if fire:
force = [ 0.0, -10.0, 0.0]
local = True
isFiring = True
#new version of GameLogic.addActiveActuator.
controller.activate(add_bullet)
#new version of getObjectLastCreated()
bullet = add_bullet.objectLastCreated
bullet.applyForce(force, local)
#the new api means that actuators are just activated or deactivated, not toggled depending on a second variable
if isFiring == True:
controller.activate(recoil)
else:
controller.deactivate(recoil)
Changed it, but didn’t help :s
And what can I do about the deprecated code?
I have only used python once or twice with the help of tutorials, so I’m still quit new to it.
##########
if fire:
force = [ 0.0, -10.0, 0.0]
local = True
isFiring = True
#new version of GameLogic.addActiveActuator.
cont.activate(add_bullet)
#new version of getObjectLastCreated()
bullet = add_bullet.objectLastCreated
bullet.applyForce(force, local)
#the new api means that actuators are just activated or deactivated, not toggled depending on a second variable
if isFiring == True:
cont.activate(recoil)
else:
cont.deactivate(recoil)
Thanks, it’s getting better.
The bullet appears. :applause:
and the animation plays. another :applause:
But there’s still something weird.
When I click once (which is the sensor fire) it keeps playing the animation and in fact it should stop after playing it once.
Secondly the bullet appears somewhere around the gun, but when releasing the mousebutton, it disappears again.
Any idea?
#with the latest 2.5* BGE you must import GameLogic
import GameLogic
#sets the script controller as cont
cont = GameLogic.getCurrentController()
# gets the sensors, now uses cont.sensors[""], not getSensor(""). also uses .positive, not isPositive()
fire = cont.sensors["fire"].positive
# gets the actuators, now uses cont.atuators[""], not getActuator("")
add_bullet = cont.actuators["add_bullet"]
recoil = cont.actuators["play_recoil"]
# variables
isFiring = False
# events #
##########
if fire:
force = [ 0.0, -10.0, 0.0]
local = True
isFiring = True
#new version of GameLogic.addActiveActuator.
cont.activate(add_bullet)
#new version of getObjectLastCreated()
bullet = add_bullet.objectLastCreated
bullet.applyForce(force, local)
#the new api means that actuators are just activated or deactivated, not toggled depending on a second variable
if not fire:
isFiring = False
if isFiring == True:
cont.activate(recoil)
if isFiring == False:
cont.deactivate(recoil)
It’s getting better and better.
But it’s not fully working yet.
The animation is working now, but the bullet’s aren’t right.
When I click, more than one bullet appears, and they don’t shoot away.
And when I release the mouse button, the bullets disappear again. :s
Character_sys.blend (632 KB)
You had the addobject time as “2” in the add object actuator. That meant the bullet lasted for 2 logic ticks i think.
Then if you want the gun to only shoot one bullet, even if you hold it-make the fire sensor a tap sensor and remove the true pulse. this attatchment does this. hope it helps
Yeah this works:p
Thanks a lot really, I couldn’t have done it myself.
Maybe another question on which I don’t know an answer, but it’s not really related to the previous topic.
Should I make a new topic or just ask it here? I will just ask it and if necessary I will make a new topic.
I actually wanted to add a map of the environment like in a lot of fps games. On which you can see your enemies and allies.
Is this possible? (probably yes) But is it a lot of trouble?
Because I’m working on a small project and a first “beta-release” should be done in a few days. So could you judge if it’s possible to get this in this amount of time?
Okay, another question (feels like a Déjà vu XD)
I wanted to and multiple characters (ennemies and allies).
They each have a turn in which they can first move and secondly shoot. (each character should use the same buttons so left mouse button to shoot).
I wanted to do this with the logic bricks since I don’t know much of python.
But this didn’t turn out well. I feel that this would be much easier in python.
Any idea how I can start with something like that?
And the second thing about multiple players… i think it is very easy to make with python. I don’t have time right now, but if you don’t get help here just PM me tomorrow.