GTA 2 style character control

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By onurbulut

I have a player RigidBody2D.I want to control it with keyboard like GTA2 character.I tried add_force() when press a key.It didnt work.It moves but when i press Left key it moves wrongfully.It should move forward when i press ‘W’ key,but when i press ‘D’ key it should turn slowly left.

My input function

func _input(event):
	if Input.is_action_pressed("ui_left"):
         add_force(Vector2(0,0),Vector2(-20, 0))
	elif Input.is_action_pressed("ui_right"): 
	     add_force(Vector2(0,0),Vector2(20, 0))
	elif Input.is_action_pressed("ui_up"):
	elif Input.is_action_pressed("ui_down"): 

I tried to change Mode of RigidBody2D to Kinematic.It doesnt move.The mode is Character.How i imlement GTA 2 style movement in Godot?

What I want
Thank you.

I couldnt add image to question.Link:Connexion | Photobox

onurbulut | 2018-10-02 21:34

:bust_in_silhouette: Reply From: MysteryGM

Character controllers rarely have actual physics, it would cause them to fall over when climbing etc.

You want a kinematic body, it allows animations etc with collisions but doesn’t have all the physics parts to mess around with: Using KinematicBody2D — Godot Engine (3.0) documentation in English

:bust_in_silhouette: Reply From: onurbulut

I solved by myself.I am sorry.Next time i will try too much to solve a problem.It seemed hard.I share the code if someone needs.

func _input(event):
	var vec=Vector2(0,0)
	if Input.is_action_pressed("ui_left"):
	if Input.is_action_pressed("ui_right"): 
	if Input.is_action_pressed("ui_up"):
	if Input.is_action_pressed("ui_down"): 


Just a heads up. If your angle is radians you can then rotate your vector2 using:

linear_velocity = vec.rotated(ang)

it is the same as calculating the sin and cos manually. Vector2 — Godot Engine (3.0) documentation in English

MysteryGM | 2018-10-03 20:43

Thanks @MysteryGM.I didnt know.Simple code is always better

onurbulut | 2018-10-04 10:36