recording the last horizontal direction player has moved?

Author Topic: recording the last horizontal direction player has moved?  (Read 1123 times)

as in, the last angle the player has moved with horizontally while ignoring vertical movement

i want to make a playertype that, when the player presses space while moving in a direction, dashes in that direction. but i don't want the player to go up a ramp or jump or whatever, then press space and suddenly fly.
« Last Edit: September 20, 2015, 12:56:55 PM by Niblic² »

Something like getWords(%player.getVelocity(), 0, 1) ?

Something like getWords(%player.getVelocity(), 0, 1) ?

how would i apply that to setvelocity?

this vector stuff confuses me


ok thanks i think ive found a good way to do it

probably not optimized but it works

Code: [Select]
%vec1 = vectorNormalize(%player.getVelocity());
%vec = VectorScale(%vec1, 30);
%vec = getWords(%vec, 0, 1);
%vec2 = getWords(%vec1, 2, 3);
%player.setVelocity(%vec SPC %vec2);

if their velocity is at an angle at 5 units, they won't go as far as if they were moving sideways at 5 units

maybe try
Code: [Select]
%vec = vectorNormalize(%player.getVelocity());
%vec = getWords(%vec, 0, 1);
%vec = vectorScale(%vec, 30);
%player.addVelocity(%vec);

i'm not sure what you were trying to do with the %vec2 = getWords(%vec1, 2, 3);

You should cut out the Z component before you normalize it, otherwise your result will be different depending on the Z component
You may also want to consider addVelocity instead of setVelocity, depending on your goal

Code: [Select]
%vec = %player.getVelocity();
%normVec = VectorNormalize(getWords(%vec,0,1) SPC 0);
%scaledVec = VectorScale(%normVec,30);
%player.addVelocity(%scaledVec);

You may also want to VectorAdd a small Z vector to %scaledVec, otherwise friction against the ground will greatly reduce the movement

ok thanks i think ive found a good way to do it

probably not optimized but it works

Code: [Select]
%vec1 = vectorNormalize(%player.getVelocity());
%vec = VectorScale(%vec1, 30);
%vec = getWords(%vec, 0, 1);
%vec2 = getWords(%vec1, 2, 3);
%player.setVelocity(%vec SPC %vec2);
use %vec2 = getWord(%vec1,2); rather than get words since there will only be words at index 0-2

use %vec2 = getWord(%vec1,2); rather than get words since there will only be words at index 0-2
Or just cut out the second vector entirely cuz I don't see what he's trying to do with that concatenation funkiness,  just replace it with "0". Or even better, don't, and look at the way I did it
I think he might be trying to
Add a small Z vector to %scaledVec, otherwise friction against the ground will greatly reduce the movement
but he's doing it the wrong way....that Z part will be 0 unless the player is already traveling vertically some, in which case it isn't terribly needed for that goal...I think it's more likely he just did random stuff until he made something that looked like it worked
« Last Edit: September 21, 2015, 06:54:09 AM by Headcrab Zombie »

Or just cut out the second vector entirely cuz I don't see what he's trying to do with that concatenation funkiness,  just replace it with "0". Or even better, don't, and look at the way I did it
I think he might be trying to but he's doing it the wrong way....that Z part will be 0 unless the player is already traveling vertically some, in which case it isn't terribly needed for that goal...I think it's more likely he just did random stuff until he made something that looked like it worked

He is preserving the z velocity, which is the correct thing to do. If you are falling, and you dash, you don't want to magically stop falling and move forwards instead.

But yeah, its much easier to use AddVelocity here.

He is preserving the z velocity
Not quite
I see why you think that, but he's getting that z velocity from the result of vectorNormalize, not getVelocity, so it's only going to be between 0 and 1
« Last Edit: September 21, 2015, 08:25:45 AM by Headcrab Zombie »

Not quite
I see why you think that, but he's getting that z velocity from the result of vectorNormalize, not getVelocity, so it's only going to be between 0 and 1

Ah, so he is.

Not quite
I see why you think that, but he's getting that z velocity from the result of vectorNormalize, not getVelocity, so it's only going to be between 0 and 1
(or -1)

i probably dont need it at all since i disabled dashing mid air