Results 1 to 19 of 19
  1. #1

    BGE any idea How replicate enemy with copy of enemy dont work

    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



  2. #2
    Member Nemescraft's Avatar
    Join Date
    Mar 2016
    Location
    Somewhere on Earth
    Posts
    214
    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!
    My game project - Scroll Tanks



  3. #3
    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.

    Code:
    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)
    Last edited by APilch; 15-Sep-17 at 10:31.
     SketchfabGame AssetsFacebookArtStation
    Ryzen 5 1400 3.2GHz, GTX 1050 Ti 4GB, 16GB RAM



  4. #4
    Member Cotaks's Avatar
    Join Date
    May 2012
    Location
    The Netherlands
    Posts
    1,185
    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()
    Last edited by Cotaks; 15-Sep-17 at 11:58.
    '- It's not working' then check your console like: this
    Did you know that you can make a complete game with the .blends that i share?



  5. #5
    Originally Posted by Nemescraft View Post
    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!
    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.

    # This is script is for free use under no license agreement

    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']

    # sensors
    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
    # aud.device().play(enemy_damage)
    # if Zstopsound.positive == False:

    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 Zstopsound.positive == False:
    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)
    # if Zstopsound.positive == False:
    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:
    # Head Shot Ray Message to ZombieCollide3
    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)
    # if Zstopsound.positive == False:
    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:


    ................
    .........................
    .................................



  6. #6
    Member JustinBarrett's Avatar
    Join Date
    Jul 2009
    Location
    Trier(near), Germany
    Posts
    2,208
    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.
    "The crows seem to be calling my name." Thought Kaw.
    Myrlea, "The Shepherd's Quest" formerly "Valiant" [project]



  7. #7
    its a copy man how you are doing if end object will end all objects



  8. #8
    Member JustinBarrett's Avatar
    Join Date
    Jul 2009
    Location
    Trier(near), Germany
    Posts
    2,208
    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.
    "The crows seem to be calling my name." Thought Kaw.
    Myrlea, "The Shepherd's Quest" formerly "Valiant" [project]



  9. #9
    Originally Posted by JustinBarrett View Post
    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.



  10. #10
    Originally Posted by JustinBarrett View Post
    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.
    In this case all copies will have a same hp property? Or will have hp1 , hp2, hp3.....



  11. #11
    Moderator Monster's Avatar
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    13,696
    Originally Posted by linuxfree View Post
    Can give me a example of pointer?
    He already did:

    Originally Posted by JustinBarrett View Post
    "owner.endObject()"
    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:

    Code:
    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.



  12. #12
    Originally Posted by Monster View Post
    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:

    Code:
    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.

    https://blenderartists.org/forum/sho...ected-update-2

    Hopefully will optimize this e will change dead animations using rag-dolls technick in update3
    Last edited by linuxfree; 08-Dec-17 at 10:17.



  13. #13
    Moderator Monster's Avatar
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    13,696
    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.
    Last edited by Monster; 09-Dec-17 at 05:21.



  14. #14
    Originally Posted by Monster View Post
    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



  15. #15
    Moderator Monster's Avatar
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    13,696
    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.
    Last edited by Monster; 09-Dec-17 at 07:47.



  16. #16
    Originally Posted by Monster View Post
    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.


    https://blenderartists.org/forum/sho...ected-update-2

    Thanks



  17. #17
    Originally Posted by linuxfree View Post
    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.


    https://blenderartists.org/forum/sho...ected-update-2

    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?



  18. #18
    Member DragonLEE's Avatar
    Join Date
    Aug 2010
    Location
    Turkey
    Posts
    220
    your enemy move to other layers. use addObject

    Code:
    scene= bge.logic.getCurrentScene() 
    scene.addObject(owner, 'Enemy Name', 0)



  19. #19
    Originally Posted by JustinBarrett View Post
    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.
    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?



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •