Fangames > Programming Questions
I need help
(1/1)
Vitellari:
I want to make that a block, when the kid touches a trigger, the block moves to a X position, for example, 1 block to the right. If you can help me, It would be very helpfull :)
infern0man1:
Set an alarm in the block that goes off when the kid touches the trigger, and when it reaches a certain coordinate, reset it's speed.
I'd do it like so:
--- Code: ---//step
if(global.trigger[num]=true){
alarm[0]=1;
}
if(x>=coordinate]){
x=coordinate;
speed=0;
}
//alarm 0
speed=[speed];
--- End code ---
There's probably a better way to do this, but yeah, it should work
Vitellari:
It didn't work :(
BaronBlade:
--- Quote from: Vitellari on November 10, 2015, 10:13:17 AM ---It didn't work :(
--- End quote ---
What exactly did you try? There are a few ways that you could have put something in incorrectly. Some screenshots or at least a description would help.
Arclooper:
It could be a difference in how the engines handle triggers if you're not both using the same one, I don't know if they all do it the same way, so you could check that.
You could also put variables for the position and speed in the create event, and if your triggered object can act in different ways other than this, also put a variable so it only moves like this when you set it to true, like:
Create
--- Code: ---xx = 0
yy = 0
spd = 0
move = false
//you can change these in the instance's creation code to the values you want to use
--- End code ---
Step
--- Code: ---if triggered == true and move == true
{
if point_distance(x,y,xx,yy) > speed
{move_towards_point(xx,yy,spd)}
else
{
x = xx
y = yy
speed = 0
}
}
--- End code ---
And if you meant for it to move instantly to the position you want simply do this in the step
--- Code: ---if triggered == true and move == true
{
x = xx
y = yy
}
--- End code ---
You would prolly still need to check for how the engine you're using deals with triggers though, just to be sure
Navigation
[0] Message Index
Go to full version