Help with nearest obj

  • dwtiger

    First please go to the debug option from c2 button and check at the left panel where it says "Hitboxes" & "Hitbox" watch the numbers now go near to any enemy and stay there and look again what happens with the numbers, you creating hitboxes none stop

    75 and 76 are the ones causing the problem, you see I warned you in my first post if you are not careful with overlapping things like this will happen, normally creating 1 object the way you do it using overlaps you always add the >> Trigger once> you can find it in the system.

    But there is another problem with this you creating already all the hitboxes on the Start of the layout Event 81 remember? so you really don't need event 75 & 76 that will create extra hit boxes for the enemies and it brake the code, an less you don't wanna create the hitboxes at the start of the layout and you wanna create them only when the player overlaps the enemy, in that case, you have to move the last three actions from event 81 to wherever place you create the

    hitbox example event 75 and adding the >> Trigger once>

    Event 81 >>replace the system create object by >> Enemies >>Spawn object>> Hitboxes and leave it in the same place order were it was the old one, I'm not sure why but it was creating the two hit boxes in the same place, but the spawn option it should fix that

    Event 84 >> you have Action destroying an Enemy but you should be destroying the Hitboxes

    Event 17 and 18 you don't need it because you already destroy the Enemies on Event 82

    Tips:

    -The Pin behavior if enemy doesn't move you don't need it

    -Remember that you have the behavior >>Line Of Sight and you can use it instead of checking for overlaps for everything

    -you have the bullet behavior for the Bullets swell

    -you have the groups to organize the code into groups and name them will help you to find bugs quicker

    probably I forgot something if I remember anything I will post it

  • Thanks again! I've fixed the issue with the multiple hitboxes for 1 enemy, I accidentally put another object in the enemy family. But now that the hitboxes are spawned in at the beginning of the layout, my bullets keep going to the wrong hitbox, is there any way to solve this? (also the enemies are still being killed all in 1)

    CapX: https://www.dropbox.com/s/itmt0kmsks26jau/RPG.capx?dl=0

  • dwtiger

    Again the same Mistakes Event 13 >> the action to add 1 to the enemy DamageTaken you add it to all of the enemies because you don't specify to which enemy belongs that hit boxes That's why you kill all the enemies in one go.

    And Event 14 have no actions in there so whats the point to put a condition without any actions on it??

    it should be like this

    Picture:

    And You did the same thing on Event 84 & 85

    Event 87 Again take damage to the enemy but which enemy all of them?? and event 88 empty why you keep leaving empty events with no actions???

    Bullets Problem:

    Event 11 you overlapping the enemy so it adds that enemy to the pick list but on the action you creating the bullet and then you move the bullet to a HitBox but the hit box is not in the pick list you don't specify to which hitbox belongs to that enemy, therefore, is an Un-Referred Object so C2 it will pick up the first hitbox created wich is Hitbox = 0

    So first replace the sprite is overlapping to >> "The Family Enemy"

    Then sub event of this event>> "Family hitbox" >>Compare>> belongsTo = To >>Enemies.UID> > Action then you can move the bullet to that angle hitbox

    Here is A picture:

    Then again you will have the same Problem with the other bullet >> Sprite36 if you don't change it, In Event 83 so do the same as above

  • Thanks! I've fixed all of those except one, I can now kill enemies one by one, but my bullets keep going to the first hitbox, how do i specify which hitbox i want my bullets to go to, cuz i want them to go to the nearest enemy hitbox.

  • Thanks! I've fixed all of those except one, I can now kill enemies one by one, but my bullets keep going to the first hitbox, how do i specify which hitbox i want my bullets to go to, cuz i want them to go to the nearest enemy hitbox.

    ????

    Did you try the example that I left in my pictures ???

    Because is working for me

  • yeah tried those, the bullet just goes to the 1st hitbox

    https://www.dropbox.com/s/9mty0n1b2sx1cvr/RPG.capx?dl=0

    I'm not sure what I'm doing wrong

  • yeah tried those, the bullet just goes to the 1st hitbox

    https://www.dropbox.com/s/9mty0n1b2sx1cvr/RPG.capx?dl=0

    I'm not sure what I'm doing wrong

    Event 12

    On the Action, you didn't choose the Family you choose the object of that family,

    you moved the sprite10 towards the (Hitbox = Object) is wrong you should move the sprite towards the (Family = Hitboxes)

    just replace (Hitbox.X, Hitbox.Y)

    by (Hitboxes.X , Hitboxes.Y)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you so much! Hopefully I'll be on a clear path to finishing this game... Eventually. I don't think I could've fixed this on my own!

  • Thank you so much! Hopefully I'll be on a clear path to finishing this game... Eventually. I don't think I could've fixed this on my own!

    Yw sir,

    cool that you are back on track

    Good luck with your game, you doing really well man keep going, One thing I will do before you go further with your project and it gets much bigger and messy you will have a hard time to find bugs, so I recommend you to stop for a few hours just to organize your code in groups before is too late, and look for things where you can optimize them

    example:

    Why use an enemy size of 280x280 when his actual size is just 36x36 ?? you are wasting x8 times more memory for each enemy when you could just put 36x36 and use the Line of sight to see if the enemies are in the range of the Player like you do with the overlap but cheaper. you will save memory and collisions checks

    Read this very carefully:

    https://www.scirra.com/blog/112/remember-not-to-waste-your-memory

    Another thing remember to keep testing performance to see if you are doing something wrong that can hurt you performance

    Create a layer call it "HUD" then click on that layer and in the left panel look for parallax change the (100,100) to (0,0)

    Now create a text in that layer HUD

    And on the event sheet add

    Every Thick: >>Txt >>set txt >>to >> "Fps: " & fps & newline & "Cpu: " & round(cpuutilisation * 100)

    so with this, you will see the fps and cpu on the screen all the time while you testing

    And here is a link for some info about Groups:

    https://www.scirra.com/manual/80/groups

  • Hi dwtiger

    I had some time free and I thought to give you a hand so I organized your capx and modified it a little bit, I touched only "Event sheet1"

    The purpose is to help you understand how to Link and Pick objects, and to better plan and optimize your events using different behaviors instead of overlaps and that will help you also in saving some Memory as you will not need to use to those big images for your enemies etc......

    Important Notes:

    Containers:

    In this Example, I use "Containers" because it's much easier to link objects with his parents or saying it differently we use less that Variable "BelongsTo"

    Here is the link to the Manual to understand more about Containers

    https://www.scirra.com/manual/150/containers

    Waits:

    "Waits" Are replaced with "Timers" Thanks to 99Instances2Go Tutorials and Help and warnings as they can cause many problems for the lack of desynchronization a simple Example: if we wanna fire up bullets every 0.2 seconds, doing it with waits it can end up in some points firing up two bullets at the same time and we don't want that

    Timers Link: https://www.scirra.com/manual/167/timer

    Functions:

    And Last I used "Functions" to better organize the events and because you can scale it up easier by adding more enemies so you will just need to modify The "Functions" and add the new Enemy to the "Family Enemies" and if this new enemy does have different Abilities or fire rate etc... just change his variable "Im_The" to what ever name you want so you will have it much easier to identify when you pick through the Functions so you can apply different abilities

    Manual: https://www.scirra.com/manual/149/function

    Some Useful Links:

    https://www.scirra.com/manual/142/families

    https://www.scirra.com/manual/75/how-events-work

    Heyy is not the best job but the purpose was more to have an overview of how everything that I mention above works, let me know if you have any questions, the capx I left it with no comments on purpose so you can study it to see how everything is linked together is the best way to learn, I hoppe it helps you

    Capx: https://www.dropbox.com/s/2uplqmxse9ky4mf/WithContainers1.ver-r244.capx?dl=0

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)