Matei511's Forum Posts

  • brunopalermo Guizmus thanks you all ! Can't believe the solution was right under my nose all the time...

  • The we need 2 consecutive actions, that you want to execute every time you need the player to switch target. It could be every 1 second, but maybe don't check this every tick, it could cost a lot if you have a high number of enemies.

    First action will check all enemies, and set a variable to remember what enemy is the closest. Let's call "EnemyID" (set to 0) and "EnemyDistance" (set to 1000000 to make this easier) the 2 variables :

    • For each object Y // we want to do this test for every enemy
    • EnemyDistance > distance(ObjectY,Player) // if the enemy we are checking is closer to the player than another before

    This will trigger a simple action that will set both variables, EnemyID to objectY.ID, and EnemyDistance to distance(objectY,Player).

    Once this loop is done, the variable "EnemyID" is set to the ID of the enemy that is the closest to the player. You can create a second action, that will select the enemy by it's ID using the variable, and ask the player to take it as target.

    i didn't quite get the last part. would you be kind enough to reformulate? I'm new to construct

  • so i have object x, the player, and 10 instances of object y , enemies. i want, on mouse pressed, for the player to auto aim to the closest enemy. Thanks in advance !

  • Add health bar to the same container where you have your bee and bee_box.

    If you place bees manually (in editor) on your layout, then simply put a bar above each bee. You need to follow the order in which they were created though - bar with the lowest UID place over the bee with the lowest UID and so on.

    In your event sheet pin health_bar to bee_box on start of layout (the same way as bee is pinned).

    That's it.

    If you create/spawn bees during the gameplay, they will be created with the health bar, because they are in the same container. You'll only have to pin it.

    Thank you, again

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's called ternary operator.

    So you have 2 lines:

    If dtp<=200 then set speed to 0

    Else set speed to 150

    You can write the same in one expression:

    Set speed to (dtp<=200 ? 0 : 150)

    dtp<=200 is a comparison statement

    ? means "if statement true then this value"

    : means "if statement false then this value"

    It's a nice little trick that can really help de-cluttering your code. You can use & and | operators , nest several ternary operators one after another and write long expressions like this:

    Set speed to (dtp<=200 | bee.IsFrozen ? 0 : (bee.IsSlowedDown ? 50 : 150))

    Set damage to (dtp<=100 ? 500 : (dtp<=200 ? 200 : (dtp<=300 ? 100 : (dtp<=400 ? 50 : 10))))

    & means AND

    | means OR

    i am running into another problem now i am trying to pin a separate hp bar over every bee. how could i do that. i tried using "for each bee" pin hpbar to bee but it pins all instances of the hp bar to one instance of a bee so i have a bee flying around with 3 hp bars that are weirdly positioned

  • It's called ternary operator.

    So you have 2 lines:

    If dtp<=200 then set speed to 0

    Else set speed to 150

    You can write the same in one expression:

    Set speed to (dtp<=200 ? 0 : 150)

    dtp<=200 is a comparison statement

    ? means "if statement true then this value"

    : means "if statement false then this value"

    Thanks a lot, you are very good at explaining

    It's a nice little trick that can really help de-cluttering your code. You can use & and | operators , nest several ternary operators one after another and write long expressions like this:

    Set speed to (dtp<=200 | bee.IsFrozen ? 0 : (bee.IsSlowedDown ? 50 : 150))

    Set damage to (dtp<=100 ? 500 : (dtp<=200 ? 200 : (dtp<=300 ? 100 : (dtp<=400 ? 50 : 10))))

    & means AND

    | means OR

  • Use "For each bee"?

    Also, you need to organize your events a bit, there are too many small events, it will very soon become hard to keep track of them.

    Move some of them under "On every tick", others under "Every 0.1s", create functions etc.

    Something like this:

    since we're at it, what does this do: bee.dtp<=200 ? 0 : 150. i don't get it after 200...

  • I made an improvement - each bee now has its own random timer when it turns around while "patrolling territory" <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    https://www.dropbox.com/s/tvibytynqy997 ... .capx?dl=0

    You can do a similar thing with bees movement speed - create an instance variable on bee or bee_box object and assign each bee a slightly different speed, at random or manually. Then use this variable when you Set Platform Speed.

    Oh, and one more thing - I combined your bee and bee_box into a container.

    wow thanks a lot mate, didn't even know "timer" exited. and i used the for each wrong, i just made a for each and out all the events containing bees in. thanks a lot.

  • Well you probably moved some event that can't be executed on every tick or did something else wrong. Just try again.

    so i stopped getting the error but still the bees act exactly the same. for example every bee is supposed to face towards the player, but they all take into acount if the player has the X coorinate smaller or larger than bee 1. All bees turn around like bee 1 is supposed to.

  • Use "For each bee"?

    Also, you need to organize your events a bit, there are too many small events, it will very soon become hard to keep track of them.

    Move some of them under "On every tick", others under "Every 0.1s", create functions etc.

    Something like this:

    Thanks for the tips. I tried for every bee but i got anerror at the beginning. The game still worked but the enemies didn't work...

  • So i managed to make an enemy AI that meets all my requirements (certain range makes him follow you, certain range makes him shoot, etc.) This works great on 1 instance. How can i apply this to more instances? Here's the capx: https://www.dropbox.com/s/k5bn3ywk6apnw ... .capx?dl=0

    Thanks in advance !

  • how do i make a player move and colide with a wall? wall is solid, checked the collision box, it's fine. object is solid, checked the collision box, it's fine. i want my player to always go towards the mouse. i have tried setting bullet but it passes through unless i use the bounce, which create san effect i don't want. and i tried move forward event. nothing works. note: i want him to always walk towards the cursor so 8 direction won't work. help would be appreciated

  • Does it do whats needed ? I coded that without testing it on a mobile device.

    not quite, but it is what i needed since the only thing i needed was that one section always controls one player. Although i don't really understand what you did there... Is there any other way to do this? where can i go to learn more about the stuff you used in there?

  • Do i have to blow in your nose to get noticed ?

    I did download your capx and i am in the process of figuring it out, since i have never used basicallt anything you have in there. It's still highly appreciated

  • I don't think I've ever heard of someone trying to do that, 4 players on the same mobile, not taking it in turns but playing at the same time? Sounds crowded. if i were to do it i'd split the screen into 4 and have 4 invisible sprites over each section, when you touch anywhere on sprite A, player A can move to any x,y within that area, touching sprite B only moves player B to any x,y within sprite B etc

    But how do i get the touch id? I tried having an instance variable called touch_id andwhen is touching area set touch_id to touch id. But i don't know how to setup touch controls that are diffrent for every player