• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

 Separate friction into hfriction & vfriction [REQUEST]

xDGameStudios

GameMaker Staff
GameMaker Dev.
As far as I know SPEED, DIRECTION, HSPEED and VSPEED are tightly connected.

For example setting the hspeed = 1 and vspeed = 1,
makes it so that GMS sets: direction = 315 and speed = 1.41...
and vice-versa...

with that in mind would it be possible to do the same for friction?
vfriction and hfriction. right now how friction works it is only applicable to top-down games.
What if I want to use friction in a platformer? friction should only be applied in the X axis.

One could argue that I can make my own physics handling, but it is just a shame to have built in system and not using it.
 

Tsa05

Member
Heyaa! This is more of a programming question than a tech support issue ;)

But let's see. Friction is simply an amount that subtracts a little from *speed* every step, right?
So if you made an hfriction variable, you could pop into the Step event and just do this:

hspeed = hspeed - hfriction;

Voila! You've got your own hfriction.
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
Heyaa! This is more of a programming question than a tech support issue ;)

But let's see. Friction is simply an amount that subtracts a little from *speed* every step, right?
So if you made an hfriction variable, you could pop into the Step event and just do this:

hspeed = hspeed - hfriction;

Voila! You've got your own hfriction.
I know how I can do that ;)
I'm not asking how it is done, I'm asking if it could be added to the built-in system.

actually the STEP EVENT should be:
Code:
if (hspeed != 0) {
    hspeed -= sign(hspeed) * hfriction;
}
I just asked the question because for example, if you want to limit a velocity (when walking diagonally), you can:
Code:
hspeed = 1;
vspeed = 1;
speed = min(speed, 1);
which means the variables as interconnected... what if I want to do something similar to the friction? (this is just an example).

I just asked for it because a lot of people seem to not use (and recommend not using) the built-in variables. And in my opinion, the problem is either in the users that don't know how to use the built-in variables or the problem is in the engine design that is not as good and it could be.

Either way, I would like to know why so many people recommend avoiding the use of built-in variables. Performance wise is not a very smart option because using it or not... the built-in variables are still processed every step.
 

Tsa05

Member
In your example, you *don't* want hfriction, you want friction. And direction.
When walking diagonally, you can:
Code:
speed = 1;
direction = 45;
This will accurately modify hspeed and vspeed, and friction will affect speed correctly.

I assumed that you wanted some kind of unequal friction, though--something that works differently on each axis. So, after you set direction and speed, you can modify each component (hspeed and vspeed) by a unique friction amount. That's why I made my suggestion.

The reason that most recommend avoiding the built-ins is, well... You noted that they are interconnected (speed, hspeed, vspeed, gravity, friction...)
And it's true--gravity and friction alter speed, speed alters hspeed and vspeed, "solids" alter all of that stuff... But not in the Step event! It happens in the weird space between frames, automatically. This makes it hard to code around; you make changes, then GM automatically adds its own.
 

slayer 64

Member
It would be neat if you could define the built in gm stuff. Like if there was a file somewhere with code in it that you could just start messing about with, and game maker's built in stuff behaved differently.
 

gnysek

Member
This is something you nearly made yourself in posts above. Shouldn't be a feature in this case, if it's easy achieveable from code.
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
This is something you nearly made yourself in posts above. Shouldn't be a feature in this case, if it's easy achieveable from code.
Yes I know it is easily achieved :)
But if you don't use the built-in stuff yourself, it will still be used...

People usually say "you can create your custom physics and avoid using the builtin"... but the builtin are still there being used used. Even if hpseed is not used and friction is set to 0 and gravity is 0 the builtin formula still is (something like):

Code:
hspeed += lengthdir_x(gravity, gravity_direction);
if (hspeed != 0) hspeed -= sign(hspeed) * friction;
vspeed += lengthdir_y(gravity, gravity_direction);
if (vspeed != 0) vspeed -= sign(vspeed) * friction;
and is still executed every single frame, isn't it?!

It would be neat if you could define the built in gm stuff. Like if there was a file somewhere with code in it that you could just start messing about with, and game maker's built in stuff behaved differently.
That would actually be a good idea, make it so we could overwrite and change the builtin calculations ;)
 

gnysek

Member
I'm more than sure that Mike / Russell will tell that it's too easy to achieve to make it internal function, except it's a special math function like they added angle_difference.
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
In your example, you *don't* want hfriction, you want friction. And direction.
When walking diagonally, you can:
Code:
speed = 1;
direction = 45;
This will accurately modify hspeed and vspeed, and friction will affect speed correctly.

I assumed that you wanted some kind of unequal friction, though--something that works differently on each axis. So, after you set direction and speed, you can modify each component (hspeed and vspeed) by a unique friction amount. That's why I made my suggestion.

The reason that most recommend avoiding the built-ins is, well... You noted that they are interconnected (speed, hspeed, vspeed, gravity, friction...)
And it's true--gravity and friction alter speed, speed alters hspeed and vspeed, "solids" alter all of that stuff... But not in the Step event! It happens in the weird space between frames, automatically. This makes it hard to code around; you make changes, then GM automatically adds its own.
what if I want friction to only be used in the X-Axis?! of just to be applied in the Y-Axis?

"It happens in the weird space between frames, automatically. This makes it hard to code around; "

If it's so weird and hard to work around, is it a good ideia to be the way it is?!
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
I'm more than sure that Mike / Russell will tell that it's too easy to achieve to make it internal function, except it's a special math function like they added angle_difference.
If it is too easy to work around, then it would be great if we could disable the built-in ones and make it so they do even get used.

Something like:
set_built_in_physics(true);
set_built_in_physics(false);

if disabled: speed, hspeed, vpseed, gravity, gravity_direction wouldn't be used and we could use them just the way we wanted :D

do you think this is a special enough function, @gnysek ?

NOTE: not being sarcastic here just wanted to know your opinion. I'm aware of how to make it happen using my own code but it would be good to enable and disable the default stuff.
 

gnysek

Member
If it is too easy to work around, then it would be great if we could disable the built-in ones and make it so they do even get used.

Something like:
set_built_in_physics(true);
set_built_in_physics(false);

if disabled: speed, hspeed, vpseed, gravity, gravity_direction wouldn't be used and we could use them just the way we wanted :D

do you think this is a special enough function, @gnysek ?

NOTE: not being sarcastic here just wanted to know your opinion. I'm aware of how to make it happen using my own code but it would be good to enable and disable the default stuff.
Remember that most of those variables were added in 1999 by Mark Overmars, and they are left only because of historical purposes.
 
Let's also not forget that "light objects" appears in the road map, so unless they are literally objects that produce light, there will eventually be that option too.
 
Top