I could of sworn that’s how it was done in Godot C#, but I just tried without it and it makes sliding down slopes possible. But it still doesn’t make bouncing off the enemy possible.
I removed lowercase velocity, in Godot C# it doesn’t allow you to edit the uppercase Velocity (the built in one) easily (so I can’t change Velocity.Y directly), so using a separate velocity variable fixes this.
Yeah the whole new Vector3(velocity.x, 10, velocity.z) thing gets annoying. Is there anywhere else Velocity is set (=) rather than added/subtracted(+=) to?
you can move StompEnemy() to
physics_process and make private.
make boolean variable to check if in this physics_process frame you stomped on enemy.
private void OnHit(Node2D body)
{
if (body is Player)
{
var Player = new Player();
Player.StompEnemy();
}
}
On you don’t want make new player, you don’t added new player to tree anyway.
if (body is Player player)
{
player.stompEnemy = true; // if stompEnemy is boolean variable, you can use first capital later if is property with {get;set;}
}
Usually, when you’re trying to modify the velocity but you notice that it isn’t visibly affecting the character, it’s because the new modifications of the Velocity property weren’t included by the MoveAndSlide() method.
So I think you should maybe try to add it as the last line of your StompEnemy() function as such:
public void StompEnemy()
{
Velocity.Y = -120.0f;
MoveAndSlide();
}
you can if (StompedEnemy)
you don’t needed check if true == true or false == true
public bool StompedEnemy = false;
private Vector2 velocity;
public override void _PhysicsProcess(double delta)
{
*(rest of the code before this)*
if (StompedEnemy)
{
StompEnemy();
}
*(code after)*
}
private void StompEnemy()
{
velocity.Y = -120.0f;
StompedEnemy = false;
}
in this move vector to to class variable and move method back to class,
other version with less code and keeping vector locally
public bool StompedEnemy = false;
public override void _PhysicsProcess(double delta)
{
*(rest of the code before this)*
if (StompedEnemy)
{
velocity.Y = -120.0f;
StompedEnemy = false;
}
*(code after)*
}