After an object is destoyed, actions that contains that object acts as if the object was at (0,0)

0 favourites
  • 6 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • So I created a simple game where the player can shoot a laser that locks on to the targets and destroys them after a certain time. However whenever I recast my laser after I destroyed all the targets, it keeps locking on to (0,0), even though nothing is there. I of course thought about putting another condition using 'AND' conditions so that the laser only fires when targets exist, but that wasn't possible because there was already an 'OR' condition there. Please help.

    Also I have another question: How do you distinguish each object? So originally I thought of casting the lasers to only the targets within a certain distance from the player, but I didn't know how to let the game distinguish the targets that are within the distance, so if I set the action to destroy the targets, it will literally destroy every target in the whole game. There definitely must be a possible way but I can't figure it out... please help.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • For your first issue you can use sub events so that you can have the AND & OR events. Make a high level event something like: Object xxx exists and then nest your other events under that.

    I just want to clarify when you say 'casting your laser' are you talking about using RayCasting?

    for the second you can use a "for each" event to apply your conditions to each instance of an object.

    so

    For Each xxx

    Is distance(xxx.x,xxx.y,laser.x,laser.y) < minimum distance - Destroy xxx

    This will only destroy the instances that meet the distance condition

  • Thanks for the reply!

    Finally solved it.... but I got another problem here. When the player dies during the laser cast (btw I'm not referring to 'RayCasting'), I wanted it to cancel the casting. The way I tried to do it was this:

    The laser itself does get destroyed when the player dies, but the enemies still get killed. I thought if you deactivate the group, it would cancel the 'wait' action and every action after it, but they still get executed....HELP

  • oh forgot to mention, lineExecute is what I call the laser ability in my game

  • 1 So I created a simple game where the player can shoot a laser that locks on to the targets and destroys them after a certain time. However whenever I recast my laser after I destroyed all the targets, it keeps locking on to (0,0), even though nothing is there. I of course thought about putting another condition using 'AND' conditions so that the laser only fires when targets exist, but that wasn't possible because there was already an 'OR' condition there. Please help.

    2 Also I have another question: How do you distinguish each object? So originally I thought of casting the lasers to only the targets within a certain distance from the player, but I didn't know how to let the game distinguish the targets that are within the distance, so if I set the action to destroy the targets, it will literally destroy every target in the whole game. There definitely must be a possible way but I can't figure it out... please help.

    on the #1 question, the turet is reseting to 0,0 cause your code has no default value to target if has no target in sight, you need to do something like if enemy.count <=0 set target to self.x,self.y or something like that or aim it at the center of screen set target to X originalwindowwidth/2 Y originalwindowheight/2 that is dead center of the screen.

    on the #2 you need to use for each enemy loop.

  • Having some difficulty following what you are trying to do. But even without knowing, your events don't make sense. When every tick is not specified, unless the event is a trigger it will run every tick anyway.

    Putting a wait three seconds action in an ever tick event means that every tick a new three second wait followed by your other actions is being executed.

    The reason all your enemies are being destroyed is because you tell them to be in event #23.

    Using a group in the way you are is not what you should be doing. You either want to have a boolean variable that determines if the laser is active, and then have events that happen if the that is true, or use a function.

    I suggest reading this section of the manual to help you get a better understanding of the basics of how the events system works.

    construct.net/en/make-games/manuals/construct-3/project-primitives/events

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