Fangames > Programming Questions

Trigger following a Timeline

(1/1)

Hop:
Hello,
I am trying to make it so when the player hits the trigger object it makes an object further down shoot up and then fall down. I can make it shoot up and fall down (similar to tossing a ball in the air) easily with a Timeline, but I don't want the timeline to start until the player reaches the trigger objects. I've approached it from several different ways, but it mostly ends with the trigger doing nothing and the object just sits there or the object triggers right away. I'm using yoyo's studio engine. 
Some help would be appreciated. Thanks.

Kyir:
Does it only need to activate once? And do you plan on having multiples of these in the same room that you want to trigger independently?

Hop:
Yeah unless you die then it would reset. Also I would like to have more than one in a room that would be activated separately and follow different timelines.

Kyir:
So this is the solution I use for things like this. I'm sure there's a more elegant way, but I haven't found it yet.

You're going to need two paired objects. I'm going to call them objLinkTrigger1 and objLinkRecieve1 for the sake of writing this, but you can go with whatever suits your style obviously. Same with the variables in the following code as long as you make sure to change every instance of them.

objLinkTrigger1 should have this code:
Create Event:
triggervar = false;

Collision with Player Event:
triggervar = true;

Then, in objLinkRecieve1 put this:
Create Event:
timelinevar = false;

Step Event:
if timelinevar = false {
    if objLinkTrigger1.triggervar = true {
        timeline_index = TimelineName
        timeline_running = true;
        timelinevar = true;
    }
}
Using this method you're going to have to make multiple linked pairs (I would call them, say objLinkTrigger2 and objLinkRecieve2) for them to be in the same room. On the plus side, that makes it easier to make each one behave in a specific way, or you could have two objects linked to the same trigger, etc. If you want to make it reset after the timeline has ended, just put a step at the end of the timeline that changes the variables in each back to their default state.

Hop:
Works perfect! Thanks :)

Navigation

[0] Message Index

Go to full version