When i killed 1 enemy killed all copy of enemy. i need create a damage property and ray to all enemies one by one?
Dont have more simple solution?
Thanks
When i killed 1 enemy killed all copy of enemy. i need create a damage property and ray to all enemies one by one?
Dont have more simple solution?
Thanks
You need to give a bit more info on what is happening. What does the script do? Is it using Logic Bricks? What are those doing?
Then people will have an easier task at solving it!
I think this will do what you want. I use this for linked enemies in my games to follow the player. You will need a ray or radar sensor named Ray and 3 actuators(Track, Motion, and an animation named Walk). You can, of course, change these to your needs.
Even if you link your enemy character from another file, it will still look for the nearest object with property âplayerâ (or whatever property you use in the ray/radar) and then run the actuators. Be sure to leave the âtrack toâ space blank in the Track actuator (found in Edit Object actuator), the script handles that.
from bge import logic
#import standard stuff
cont = logic.getCurrentController()
own = cont.owner
#import the sensors and actuators
Ray = cont.sensors['Ray']
Track = cont.actuators['Track']
Motion = cont.actuators['Motion']
Walk = cont.actuators['Walk']
if Ray.positive:
# get a list of objects that have been hit by the near sensor
hitObjs = Ray.hitObjectList
dist = 0
obj = None
# Iterate over the list to find the closest object
for item in hitObjs:
if item.getDistanceTo(own) < dist or dist == 0:
dist = item.getDistanceTo(own)
obj = item
# Assign the actuator to track to obj, then activate the actuator.
Track.object = obj
cont.activate(Track)
cont.activate(Motion)
cont.activate(Walk)
When i killed 1 enemy killed all copy of enemy
If you use script mode (like the script from APilch) then that script can be used by 1 object only, if more are running it you indeed kill all objects that uses that script.
The solution
use functions and the module mode in the python brick.
Easiest way is creating a script for the player and just put a property on the enemy.
then you can check when shooting if you hit an enemy, then subtract health and in the same script you check if ray[0][âhealthâ] <= 0 then you kill the ray.hitObject.
for an example look into my sig and grab the fps bundle.
head to weapon.py and go see function shoot()
yes i using script bullet_hit with Ray camera in player to get hit and damage state of enemies
my problem is i have 4 enemy entities and worked with diferent properties enemy1, enemy2, enemy3, enemy4 but work only 4 enemies per time
in run time and i need 15 or 20 like in crimson earth unity game. How can replicate or i will need create 20 properties and 20 entities for work in run time?
I just using respawn point empty object but need execute dead animation to appear in other spawn point and work 4 only enemies in same time. I need
15 or 20 more.
from bge import logic as GameLogic
from mathutils import Vector
import aud
c = GameLogic.getCurrentController()
own = c.owner
scene = GameLogic.getCurrentScene()
space = 0.03
gunspawn = scene.objects[âgunspawnâ]
#zombie damage sound
#enemy_damage = aud.Factory.file(â/media/root/96ACDD05ACDCE0B3/MakeHumanZip/project_last_back/sounds/zombie_damage.oggâ)
enemy_damage = aud.Factory.file(GameLogic.expandPath(â//sounds/â + âzombie_damage.oggâ))
#shot_mask = aud.Factory.file(GameLogic.expandPath(â//sounds/â + âshotmask.oggâ))
#propertie
live = own[âliveâ]
live2 = own[âlive2â]
live3 = own[âlive3â]
live4BX = own[âlive4BXâ]
live4 = own[âlive4â]
Killed = own[âKilledâ]
Killed2 = own[âKilled2â]
TotalKilled = own[âTotalKilledâ]
DamageWait = own[âDamageWaitâ]
healthplayer = own[âhealthplayerâ]
Ray = c.sensors[âRayâ]
Ray2 = c.sensors[âRay2â]
Ray3 = c.sensors[âRay3â]
Ray4 = c.sensors[âRay4â]
Ray5 = c.sensors[âRay5â]
Ray6 = c.sensors[âRay6â]
Ray7 = c.sensors[âRay7â]
Ray1_hshot = c.sensors[âRay1_hshotâ]
Ray2_hshot = c.sensors[âRay2_hshotâ]
M24flare = c.sensors[âM24flareâ]
Glockflare = c.sensors[âGlockflareâ]
#knife sensors
kray1 = c.sensors[âgroundknifeâ]
kray2 = c.sensors[âenemyknifeâ]
kray3 = c.sensors[âenemy2knifeâ]
kray4 = c.sensors[âenemy3knifeâ]
#Near Active HeadShot SENSOR
ActiveHeadShot = c.sensors[âActiveHeadShotâ]
#zombie sensor
Zstopsound = c.sensors[âZstopsoundâ]
#Ray4
if own[âDamageWaitâ] == False:# this is for a Zombie Air Attacj player cant damage till zombie back to PLANE
if Ray4.positive and Glockflare.positive and gunspawn['equiped'] == 2 and live3 > 0 or Ray4.positive and M24flare.positive and gunspawn['equiped'] == 1 and live3 > 0:
#damage enemy sound
if live3 < 51:
aud.device().play(enemy_damage)
c.activate(DecLive3)
# Get info
pos_vec = Vector(Ray4.hitPosition)
normal_vec = Vector(Ray4.hitNormal)
# make object
if live3 > 50:
blood.instantAddObject()
bullet_hole = blood.objectLastCreated
# position hole
bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
normal_vec.magnitude = 0.03
bullet_hole.worldPosition = (pos_vec + normal_vec).xyz
# make object
body_hole.instantAddObject()
bullet_hole3 = body_hole.objectLastCreated
# position hole
bullet_hole3.alignAxisToVect(normal_vec.xyz, 2, 1)
normal_vec.magnitude = 0.003
bullet_hole3.worldPosition = (pos_vec + normal_vec).xyz
#enemy 3
if own[âDamageWaitâ] == False:# this is for a Zombie Air Attacj player cant damage till zombie back to PLANE
if own['healthplayer'] > 0:
if kray4.positive and gunspawn['equiped'] == 3 and single.positive and timer == 0 or kray4.positive and gunspawn['equiped'] == 3 and knife.positive and timer == 0:
#damage enemy sound
#aud.device().play(enemy_damage)
if live3 < 51:
aud.device().play(enemy_damage)
c.activate(DecLive3)
# Get info
pos_vec = Vector(kray4.hitPosition)
normal_vec = Vector(kray4.hitNormal)
# make object
if live3 > 50:
blood.instantAddObject()
bullet_hole = blood.objectLastCreated
# position hole
bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
normal_vec.magnitude = 0.03
bullet_hole.worldPosition = (pos_vec + normal_vec).xyz
# make object
body_hole.instantAddObject()
bullet_hole3 = body_hole.objectLastCreated
# position hole
bullet_hole3.alignAxisToVect(normal_vec.xyz, 2, 1)
normal_vec.magnitude = 0.003
bullet_hole3.worldPosition = (pos_vec + normal_vec).xyz
if Ray7.positive and Glockflare.positive and gunspawn[âequipedâ] == 2 or Ray7.positive and M24flare.positive and gunspawn[âequipedâ] == 1:
#damage enemy sound
aud.device().play(enemy_damage)
c.activate(DecLive4)
own.sendMessage('Bullet_Impact') #zombie_collide3
# Get info
pos_vec = Vector(Ray7.hitPosition)
normal_vec = Vector(Ray7.hitNormal)
# make object
blood.instantAddObject()
bullet_hole = blood.objectLastCreated
# position hole
bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
normal_vec.magnitude = 0.03
bullet_hole.worldPosition = (pos_vec + normal_vec).xyz
# make object
body_hole.instantAddObject()
bullet_hole3 = body_hole.objectLastCreated
# position hole
bullet_hole3.alignAxisToVect(normal_vec.xyz, 2, 1)
normal_vec.magnitude = 0.003
bullet_hole3.worldPosition = (pos_vec + normal_vec).xyz
if ActiveHeadShot.positive == False:
if Ray1_hshot.positive and Glockflare.positive and gunspawn['equiped'] == 2 or Ray1_hshot.positive and M24flare.positive and gunspawn['equiped'] == 1:
#damage enemy sound
aud.device().play(enemy_damage)
#c.activate(DecLive4)
#own.sendMessage('Bullet_Impact') #zombie_collide3
own.sendMessage('Head_Shot1') #zombie_collide3 Killed by 1 head shot
# Get info
pos_vec = Vector(Ray1_hshot.hitPosition)
normal_vec = Vector(Ray1_hshot.hitNormal)
# make object
blood.instantAddObject()
bullet_hole = blood.objectLastCreated
# position hole
bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
normal_vec.magnitude = 0.03
bullet_hole.worldPosition = (pos_vec + normal_vec).xyz
# make object
body_hole.instantAddObject()
bullet_hole3 = body_hole.objectLastCreated
# position hole
bullet_hole3.alignAxisToVect(normal_vec.xyz, 2, 1)
normal_vec.magnitude = 0.003
bullet_hole3.worldPosition = (pos_vec + normal_vec).xyz
#Active Mask for ZombieCollide3
if ActiveHeadShot.positive == True:
................
âŚ
âŚ
Seems like you might be going about this the wrong wayâŚI would create one script and attach it to one enemy, forget about the enemy1 enemy2 enemy3 system, you are just asking for troubleâŚ
get the one enemy to work, then simply make copies of that enemyâŚ
I myself am not using a raycast I check if the object in fron of the player has a property 'hp' and if I attack, I reduce the 'hp' in the target object....
The object itself is reponsible for removing itself if itâs hp < 1âŚown.endObject(), but before that the enemy will reward the player with xp or some drop or somethingâŚTHEN call endObject()âŚ
The other enemy copies should not be affectedâŚI hope I am understanding what you are trying to do.
its a copy man how you are doing if end object will end all objects
endObject() is a function that ends one object with a âpointerââŚ
like âowner.endObject()â this will end the object that is running the logic with this scriptâŚdoes this make sense? pointers are a bit abstract and if you do not have any coding experience it is just a way of letting the engine know which object(when they can all be similar) you are trying to referenceâŚâpointerâ is not really the best term in this caseâŚbut it is the best I could think of ATM.
If you are new to BGE I really reccomend that you start smallâŚget one small thing to work in your game, then move on to the next small thingâŚuntil you have a portrait of small things to create a masterpiece.
Can give me a example of pointer?
Or module functions where work of copies of same object
I,m using raycast and need create new ray for every object copied then many expensive time and lines with script.
In this case all copies will have a same hp property? Or will have hp1 , hp2, hp3âŚ
He already did:
Owner is a reference to a game object (typically the owner of the currently running controller). Therefore you end the game object referred by the variable owner.
Other example:
hitObject = raySensor.hitObject
hitObject["hit"] = hitObject.get("hit",0) + 1
hitObject is a variable that refers to the game object provided by the raySensor.
The second line sets/changes the property âhitâ of hitObject.
You might notice that you get the object without any relation to the object name. The relation is that it was detected by the raySensor.
In this case can I add many objects with empty object in logic bricks and use
The script for just check if ray camera of player in front of object and with atack damage just this object but another dont will affected? But property hp is one for all copies object?
Here is my update 2 from my game but using objects with raycast one by one many expansive time doing this.
Hopefully will optimize this e will change dead animations using rag-dolls technick in update3
When you refer to an object in a logic brick (via GUI) it means it is a static setup. You can dynamically change the setup via python. Keep in mind on sensors it will be considered within the next frame (as the sensors are already been processed within the current frame). Changing the actuator configuration will be considered within the current frame. It might be you need to activate the actuator again.
This is different to the result of a sensor, which is freshly calculated at each frame.
In this can i stay the old enemies and create one new copy but don using more de raysensor from logic brick go start via python for see what result i will get.
In python 1 raySensor will made work i need just load this script in to the Camera Player contoller when Fire mouse button if raysensor in object will made a damage or dead enemy and copies will not be affected more this?
Just create a new script with just 2 lines of you post me?
Code:
hitObject = raySensor.hitObject
hitObject[âhitâ] = hitObject.get(âhitâ,0) + 1
Thanks
You measure from player rather than from enemy (when shooting from player).
You need exactly one raysensor that measures what was hit. The hitObject is the enemy (or the enemies hit box) that gets hit.
Now you know the shooting character (player) and the hit character (hitObject). From here you can calculate the damage, health, points and whatever of both involved characters.
If the enemy is shooting you need a sensor at the enemy that measures what was hit. It is pretty much the same setup.
If you need something more for imagination. Think about you are the player. You point with your finger in front of you (=ray sensor). Whatever your finger is pointing at, this is hit. While you stay the same all the time, the hing you point at changes.
Yes in old enemies I have the body cube sensor and head cube sensor.they are zombies please see the video friend.I will made a new copy just for start and go create new script.I have old bullet_script go stay for old enemies and go try use this new for new copies of zombies will need create new health new damage property i think too.in update 3 will try work with ragdolls walk pathfind, attack and dead zombies actions.
Please look update 2 need dead enemy for can respawn i hope can solve this with your idea.
Thanks
Please give me explain when i said make many copies is add object many times in real time and shot one by one and damage and kill one by one same object added many times in real time right?
your enemy move to other layers. use addObject
scene= bge.logic.getCurrentScene()
scene.addObject(owner, 'Enemy Name', 0)
In this i dont make more end_object using logic brick but with script function right?Can just create a heath property or health variable and if ray camera player positive to the target object and mouse left positive heath -= 10 example
And a copy or object added many times with empty pos dont be affect more right?
I use a player camera ray right set to property o enemy i wish shot In my enemy i create a health integer property with value 100
but not working the script in Camera Ray when press P said the heath property is not defined in debug health appear 0.00000000
My script is not in enemy object is in player camera object may be this is causing error?
Can you help me?
need use like this?
my_property=scene.objects[âother objectâ][âotherpropNameâ]
then script not need stay in enemy object?