Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | dayo05 |
I’m new to use godot engine and I also friendly with Unity so I prefer to use C# as scripting language.
I’m trying to move player via key input.
I applied Rigidbody2D Node to player and I use this code to move player.
var t = false;
if (Input.IsActionPressed("ui_right") && (t = true))
//AddCentralForce(Vector2.Right * MovingBias);
LinearVelocity = new Vector2(MovingBias, LinearVelocity.y);
if (Input.IsActionPressed("ui_left") && (t = true))
//AddCentralForce(Vector2.Left * MovingBias);
LinearVelocity = new Vector2(-MovingBias, LinearVelocity.y);
if (!t) LinearVelocity *= Vector2.Down;
if (Input.IsActionPressed("ui_up"))
//AddCentralForce(Vector2.Up * 5);
LinearVelocity = new Vector2(LinearVelocity.x, -20);
//RotationDegrees = 0;
base._IntegrateForces(state);
I enter this code to _IntegrateForces to avoid cross-thread issue.
Also, I made my custom map with Tilemap.
My issue is this.
When I press up arrow, it works fine. But in right/left arrow on tile, Player sometimes stuck on when collision changed.
This is the issue what I met: YouTube video (Just for more information, Vectors of output console is the speed and right part is my player.)
Thanks for your help.