I have a character that moves by using the velocity:
rb.velocity = new Vector2(move * maxSpeed, rb.velocity.y);
This works fine, except for platforms with a Surface Effector 2D. I think the surface effector adds Force to the player, but that gets ignored because I set the velocity manually.
If I use AddForce to move the player, the Surface Effector does work, but then I get acceleration when I keep the cursor keys pressed… I don’t want acceleration!
rb.AddForce(new Vector2(move * (maxSpeed/10), 0), ForceMode2D.Impulse);
How can I use Surface Effector on characters that set their velocity?
Somewhere that velocity blend has to happen. Perhaps you can make your own surface effector with a trigger, which would then have code to add to the above velocity you’re setting. I assume it is for something like a conveyor belt or wind… might want to look up tutorials on doing those sorts of things in 2D on Unity.
I followed this tutorial:
Maybe I can just add to the existing velocity, up to a certain speed, so that I don’t get acceleration just by moving.
if(rb.velocity.x + move > -4f && rb.velocity.x + move < 4f) {
rb.velocity = new Vector2(rb.velocity.x + move, rb.velocity.y);
}
Now the surface effector works, but movement is a bit erratic, only adding movement when the character has slowed down to 0…