Godot 4
My characterbody2d is a plane so I don’t want it to stop in mid air, how can i set a minimum speed so it’s not stopped completely?
(I’ve tried velocity = Vector2(10, 0) however, this only moved my character to the right when I want it to move at a minimum speed the way it is facing)
Blockquote
Blockquote
This might depend a bit on how you’ve implemented your character (I’m imagining it is being viewed from above and can freely rotate?) but you can get a local vector in CharacterBody2D by using some_vector.rotated(rotation). For example, to get a normalised (length 1) vector pointing to the right relative to character’s current rotation you can use:
Vector2.RIGHT.rotated(rotation)
If the front of your plane faces up, you’d use Vector2.UP instead of Vector2.RIGHT.
Once you have a local forward vector you can multiply it by a float (such as your desired speed) to get a vector which represents going forward at that speed. This might be all you need, as it would replace the “Vector2(10,0)” that you mentioned above.
To get the current forward speed you can use velocity.rotated(-rotation).x or .y depending on which axis is forward for you. The x or y you didn’t use will be the lateral speed. You can manipulate these as you wish and then rotate the back if you wish to assign it to velocity, though there are probably more performant ways to do this.
Make sense?
edit: Removed/rewrote half of this because, no, it didn’t make sense. This is what happens when I post while tired! Hopefully what remains is still useful to you.