A frontal Gatling gun parented on an empty that is also parented to the helicopter
A near sensor on the helicopter
A motion actuator for the Gatling gun to rotate on its Y axis (fire animation)
Test cube with a property ENEMY, searched by the near sensor
A material TEAM COLOR is asigned to some parts of the model
@ 1 - Is there a good way for the Gatling gun to rotate to the object with the property ENEMY when it is in the range of the near sensor (if multiple enemies - track nearest) ?
@ 2 - Is there a way to add a rotation constraint for the Gatling to not rotate up past a certain rotation value (I.E. not going height that 1.5 on X axis (same for left and right rotation) ?
@ 3 - Is it possible to make it a light a possible since the helicopter is going to be one of many others spawned on map.
@ 4 - Is it possible to change the TEAM material color via a script or logic bricks (8 base colors: red/orange/yellow/green/cyan/blue/purple/white) ?
*** Requirements: make it work with only logic bricks and/or a little python scripting as possible.
***@ + bold = done
Underlined = bugs/not working
Blank = not answered/solved
***# New questions might be added to the thread since I might not be the only one to have these bugs/problems/errors. #
If it’s not a problem, please specify the question number before answering, it is much appreciated.
I will answer to question number 1:
I think it is not that easy to pick the nearest enemy, the near sensor will just pick a random one I guess, but I think thats ok.
So what you have to do is:
-add an always sensors with true pulse enabled
-add the near sensor with the enemy property filled in and call it “near”
-connect both to a python controller
-set the script type in the controller to module and type “tracking.main”
-now add an edit object actuator and set it to track to (do not fill in an object name) and call it “track”
-connect it to the controller
-add a new textblock and call it tracking.py
-copy and paste this script:
from bge import logic
def main(cont):
own = cont.owner
near = cont.sensors["near"]
track = cont.actuators["track"]
if near.positive:
track.object = near.hitObject
cont.activate(track)
else:
cont.deactivate(track)
@ Fluppi393: the only downside is that when the enemy gets out of the near sensor range the rotation doesnt resets, i guess there is a way to fix it by adding a function in the else section - but I don’t know what it is …
(it’s only been 2 months that i started using blender)
Have another empty parented to a fixed point (an object that won’t be rotating with the Gatling gun) and call it “idle”. Then, add another “Track To” actuator, make it track to the idle empty, connect it to the Python controller, and call that one “idle” as well. (Don’t use the quote marks. :P) Finally, the script I’d use:
from bge import logic
def main(cont):
own = cont.owner
sen = cont.sensors
act = cont.actuators
if sen['near'].positive:
act['track'].object = sen['near'].hitObject
cont.deactivate(act['idle'])
cont.activate(act['track'])
else:
cont.activate(act['idle'])
cont.deactivate(act['track'])
(I like to have variables for all actuators and all sensors on the controller, instead of just naming certain ones, in case I want to add something to the script.)
Hope this helps!
I don’t know if this will help, but here is a blend with a short script that gets all the objects with a property “Enemy”, adds them to a dictionary along with their distance from the camera, and finally sorts it from the closet to farthest. If the script was hooked to like a tracking actuator you could assign it the closet enemy by using nameOfActuator.target = sortedEnemies[0] I believe.
i don’t know how it could work, but for your problem with returning to its original position, you might be able to place an empty in front of the gun and when there isn’t any enemies close enough just track to the empty
Thanks to all of you guys.
@ scuba111223: I think its gonna do the trick.
@ blueprintrandom: its nice but I guess I might have to do python scripting since it is more versatile.
1: That would take a certain knowledge of either constraints or Python that I regret to say I don’t have.
2: Make different model objects, once for each colour of each object you want to be teambased (so a total of 8 different helicopters, all with different materials for different colours) and on your main objects, use the Edit Object > Replace Mesh actuator to change the mesh depending on what team your heli is on.