(Fixed) Enemy pushback different from given value

demonipo

Member
When i first programmed the collisions with the enemies, it worked exactly how I wanted. But, it recently derailed and now it is fixed on (-)5 and not (-)10 . I thought it could be about the speed limits i put but all of them are (-)10 or above. I changed the values on the collision but it still fixed on (-)5. I checked if i put anything on obj_enemy but it's blank. I don't know where i messed up and, no matter how many times i read the code, it always seems it is correct.

Code:
if vspd < 0 and time = false
    {
            vspd = +10
    }
            else
            {
                if hspd > 0
                {
                    hspd = - 10
                }
                    else
                    {
                        hspd = + 10
                    }
            }           
}
the positive collision with the object works, but the horizontal is halfed

[vspd is vertical speed, hspd is horizontal speed, time is to check if the character is flying]

Besides that, i have a air dash, boost, float and flying mechanics that make the character lose its collision with the enemy's, but still makes it take damage. Do i have to put the mechanics variable in front of every "If"?
 
Are you trying to add or take 10 away from these variables? Because that is not how you do that. Either:
Code:
vspd += 10;
Or
Code:
vspd = vspd+10;
Is how you perform addition (with the same for subtraction, multiplication or division).
 

demonipo

Member
Guess who has forgot this thread? (I'm a disgrace).

Anyway,

Do you have something like friction that cuts hspd in half every step?
I don't have anything that halves anything. Furthermore, I don't have anything that that cuts or multiplies anything, which makes this situation super strange. As I (probably) said, I have speed caps for any situation that involves horizontal speed. The normal speed cap is at 10, when the player longjumps it's 15, and when he dashes or boosts it's 20. Should I make a speed cap for when there is enemy contact to see if it becomes the value I want?

Are you trying to add or take 10 away from these variables? Because that is not how you do that. Either:
Code:
vspd += 10;
Or
Code:
vspd = vspd+10;
Is how you perform addition (with the same for subtraction, multiplication or division).
I probably didn't make myself clear, so sorry for that (and the super late response). I don't want to add or take, I want to substitute the current horizontal value for (-)10. I have used those operations with other variables, but thanks for writing it though.
 

demonipo

Member
Time to post all your movement related code as the issue is not in the snippet you provided.
Really? Well, this is going to be fun! :bash:
Atleast i know it's not the enemy collision event so that's already some improvement.

Code:
//*******************************************************************************************************
//******************************************Movement*****************************************************
//*******************************************************************************************************

//speed caps

//Normal movement

if dash = 0 and special = 0 and boost = 0 {
        if hspd > 0
        {
            if hspd > spd hspd = spd
            }
            if hspd < 0
            {
                if hspd < -spd hspd = -spd
                }
        }

//Long Jump speed cap

        if special = 1
        {
                    if hspd > 15 hspd = 15
                    if hspd < -15 hspd = -15
        }

//Boost Cap

if boost = 1
{
    if hspd > 20 hspd = 20
}
else
{
if hspd < -20 hspd = -20
}

//Dash cap

if dash = 1
    {
        if rkey
        {
            if hspd > 20 hspd = 20
        }
        if lkey
        {
            if hspd < -20 hspd = -20
        }
}

//moving right

if (rkey) {
hspd = hspd + 0.15
}
if (rkey) and hspd < 0
hspd = hspd + 1.25

//moving left

if (lkey) {
hspd = hspd - 0.15
}
if (lkey) and hspd > 0
hspd = hspd - 1.25

//check for not moving

if ((!rkey && !lkey) || (rkey && lkey)) {
    if hspd < 0 hspd = hspd + 1
    if hspd > 0 hspd = hspd - 1
}
if ((!rkey && !lkey) || (rkey && lkey)) {
    if hspd < 0 && hspd >= -1 hspd = 0
    if hspd > 0 && hspd <= 1 hspd = 0
    }
    
//*******************************************************************************************************
//******************************************Collisions***************************************************
//*******************************************************************************************************

//horizontal collisions

if (place_meeting(x+hspd, y, prnt_obj_solid))
{
    while (!place_meeting(x+sign(hspd),y , prnt_obj_solid))
    {
        x+= sign(hspd)
        }
        hspd = 0
        }

//move horizontally

x += hspd
Hopefully the comments make it clear what the variables do. BUT just in case:

Special is for the longjump
Boost is for boost (lol)
dash is for dash (^)
hspd is horizontal speed

I did not put any movement that is related to the Y-Axis because, IF I'm not mistaken, the problem comes from horizontal thingamajigs
 

Relic

Member
What is the value of spd? Hspd is limited to that value under “normal movement”.

Shouldn’t be the issue here, but under the “Boost” section your bracket placement will result in a negative hspd being capped at -20 only if boost is false.

When the player has collided and is moving at -10, holding the right key will increase hspd by 0.15 then next line by 1.25 for a total of 1.40. It will only take around 7 game steps to get back to a positive hspd - hard to notice the knock back effect.

How do you know the hspd is halved on a collision?
 

demonipo

Member
1- Spd is the maximum "normal velocity" which is set to 10.

2- the boost is working correctly from what I've seen with me and my friends whom tested the game. I'll fix it tomorrow.

3- so what you're saying is that my object is getting back to contrary speed to quick? I honestly believe that. A common complain was that the game felt slippery so I shortened the acceleration and increased deacceleration. Maybe because of that my character is going back for round 2 quicker than I wanted.

4- I'm using Draw GUI to check multiple variables while testing to see if everything is right. When I collide with the enemy, it makes the character speed (-)5. I changed the values and it was stuck on 5. I did say half to which I am sorry, I misguided everyone who tried to help to look for a division and not a set value.

5- F this text box on Android.
 

demonipo

Member
I was doing some research to how I could make the character not go back to normal immediately and I think I found a solution.

Maybe, if I do a obj_player_damage which will have no inputs switch with the normal player object, the character may go back without a chance of reducing the push-back. However, the value will still be 5.

Another thing that may work would be to reduce deceleration values, since they are pretty high (imo). It could make the value go back to 10, but I need to try it later today.

What do you guys think?
 

Relic

Member
I tend to set some flag or another state in my player object that, like you said, ignores inputs for a bit. Has other functions like won't take any further damage from enemies during this state too. Sorry, no eureka moments regarding your hspd=5 issue.

If you haven't already, get comfortable with using the debugger. Set a break when the collision occurs. Let the game run and once the break is triggered, set a few more breaks in player step event to step through important lines of code to see how hspd is affected soon after a collision.
 

demonipo

Member
I think I'll just go cry in the corner for a bit with this hspd 5 problem.

I have never used the debugger to be honest. I don't understand some of it functions so I need to get used to it. I'll try to see if there is a eureka moment with the debugger. (probably not, but it's worth the try)

Maybe if I do a flag that when activated makes my character turn into obj_hurt that has a adaptive 10 hspd until it hits the ground
 
D

Danei

Guest
Just put your player in a state that doesn't accept inputs and/or overrides your character's velocities directly. This can be as easy as putting an if-else block around your movement code. There's no need for a separate object, and if you use one it is likely to complicate other aspects of your code down the road, in my opinion.
 

demonipo

Member
Just put your player in a state that doesn't accept inputs and/or overrides your character's velocities directly. This can be as easy as putting an if-else block around your movement code. There's no need for a separate object, and if you use one it is likely to complicate other aspects of your code down the road, in my opinion.
working on something like what you just wrote, gonna see how it goes.
 

demonipo

Member
it is working. kinda. I guess the 5 came from all the values that shrunk the velocity and limitated it. it went from 5 to 8ish. followed what danei said and it is working pretty well. gonna try and perfect it tomorrow. thanks guys (and gals).
 
Top