The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

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.

in Engine by (21 points)

2 Answers

+1 vote
Best answer

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"): 

by (21 points)

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.

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

+1 vote

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:

by (1,492 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.