SOLVED Change of player's speed on any collision

lock46

Member
When the player eats something, the character will speed up for a while. How do we do that?

The player's walksp is 3.5, if the player collides with adrenaline, walksp += 2 for 15 seconds, so how can we do this? Can you help me?

tıtıtıtıııtıtıtıtıtııtıtı.png
 

woods

Member
if the player collides with adrenaline, walksp += 2 for 15 seconds,
i would go something along these lines..
psudo-code
Code:
//player create event
walkspd = 3.5


//player step event
if place_meeting(x,y,obj_adrenaline)
{
walkspd = 5.5;
alarm[0] = room_speed * 2;
with other
    {
    instance_destroy();
    }
}


//player alarm[0] event
walkspd = 3.5;
 

Joe Ellis

Member
I would use a separate variable called "my_speed" which is used for the current speed the player has.
When it collects powerups you can change this variable without messing up the other ones like walk speed, run speed, super mode speed etc.

So you can simply make a collision event with obj_adrenaline and do:
GML:
my_speed += 2;
alarm[0] = 60 * 15;
Then in the alarm[0] do:
GML:
my_speed -= 2;
And if ever you need to set the my_speed back to standard walk speed you can just do my_speed = walk_speed.

Edit- I just realized this is exactly what woods said apart from the separate my_speed variable thing! The code is exactly the same. Sorry @woods I got carried away, I just love coding so much
 

lock46

Member
i would go something along these lines..
psudo-code
Code:
//player create event
walkspd = 3.5


//player step event
if place_meeting(x,y,obj_adrenaline)
{
walkspd = 5.5;
alarm[0] = room_speed * 2;
with other
    {
    instance_destroy();
    }
}


//player alarm[0] event
walkspd = 3.5;
ERRORS:
walkspd is wrong actually walksp instance destroy is wrong because when player collides with adrenaline, player is destroyed

---------------------------------------------------------------------------------------------
The player collided with adrenaline and accelerated, that's what I wanted but the player collides with adrenaline but the adrenaline not destroy, I want adrenaline for once, how can I do it
 
Last edited:

woods

Member
walkspd, walksp, walk_spd... whatever variable you want to use... its your game
so long as its the same variable in the create, and step events we could call it "as_fast_as_joe_wants_to_go" ;o)

the scope should change with using "with other" to the colliding instance, instead of the calling instance... so in this case, the "other"would be obj_adrenaline.. ...right?
with other
{
instance_destroy();
}

tho this should pretty much do what you are asking.. might have to fiddle with it a bit to make it work exactly how you want.. (thats what the psudo-code means... "kinda like this")


post your code that you have and we can try an help further ;o)
 

TheouAegis

Member
Because woods' code just used "if place_meeting()", which does not change the scope of "other" because it is not a collision event nor a with loop.


GML:
//player step event
with instance_place(x,y,obj_adrenaline)
{
    other.walkspd = 5.5;
    other.alarm[0] = room_speed * 2;
    instance_destroy();
}
 

lock46

Member
Because woods' code just used "if place_meeting()", which does not change the scope of "other" because it is not a collision event nor a with loop.


GML:
//player step event
with instance_place(x,y,obj_adrenaline)
{
    other.walkspd = 5.5;
    other.alarm[0] = room_speed * 2;
    instance_destroy();
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
it worked thank you all!
 
Top