# Need Help Manipulating Rigidbody2D According to Analog Stick!

**URL:** <https://forum.godotengine.org/t/need-help-manipulating-rigidbody2d-according-to-analog-stick/124025>\
**Category:** Physics\
**Tags:** game, godot-4, gdscript, 2d\
**Created:** [October 3, 2025, 8:21am UTC](https://forum.godotengine.org/t/need-help-manipulating-rigidbody2d-according-to-analog-stick/124025 "2025-10-03T08:21:53Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Snip\_Nineteen](https://forum.godotengine.org/user_avatar/forum.godotengine.org/snip_nineteen/32/58470_2.png) [@Snip\_Nineteen](https://forum.godotengine.org/u/Snip_Nineteen)\
**Post date:** [October 3, 2025, 8:21am UTC](https://forum.godotengine.org/t/need-help-manipulating-rigidbody2d-according-to-analog-stick/124025/1 "2025-10-03T08:21:53Z")

</div>

### Godot Version

`Godot v4.5 `

### Question

Hi everyone! I’m working on a game right now and am facing an issue with the basic movement engine. Essentially, I want a system where a RigidBody2D can be moved around using another RigidBody2D as a “leg”, with that leg’s extension and direction controlled with the analog stick.

Here’s a basic sketch of what I want to do, where the leg can be used to vault the player forward:

 ![1759384831-111436-ex](https://forum.godotengine.org/uploads/default/original/3X/b/c/bc50ded78ab8000925bec1f35e7a605056836f76.png)

(It’s not unlike that game “Getting Over It”, or its inspiration game “Sexy Hiking” lol)

So here’s my scene setup for the player. (The scene setup for the world is just a simple StaticBody2D. The leg is on a second layer that should also be able to interact with the ground so it doesn’t collide with the main body.)

 ![1759384943-430534-image](https://forum.godotengine.org/uploads/default/original/3X/b/a/bad31d22598cda342dc6df3ac4b44b581e84f2af.png)

And here’s the code I’ve written to try to accomplish the effect.

```auto
extends RigidBody2D

func physics_process(delta: float) -> void:
	var input_vec: Vector2 = Vector2(
	Input.get_joy_axis(0, JOY_AXIS_RIGHT_X),
	Input.get_joy_axis(0, JOY_AXIS_RIGHT_Y)
)

	position = input_vec * 60
	rotation = input_vec.angle() + deg_to_rad(90)

```

And finally, here’s what’s happening when I try it.  
 ![1759385370-115528-planter](https://forum.godotengine.org/uploads/default/original/3X/e/f/ef793732845cb697e0cb277e5b1f58546614c43b.gif)

As you can see, the leg isn’t interacting with the ground at all. Afterward, I tried a solution where I got rid of the second rigidbody and just attached the code to a CollisionShape2D. (Same code as before, just change extends RigidBody2D to extends CollisionShape2D.) This time, the body part did interact with terrain, but it was janky and unwieldy.  
 ![1759385807-323640-planter1](https://forum.godotengine.org/uploads/default/original/3X/1/8/1840218e3003f0c84fa84351b43d11d57ef36abb.gif)

When I tried locking the rotation of the parent node with this setup, I was able to get something less glitchy, but now the body could no longer move and was stuck in place like this.  
 ![1759385986-294034-planter2](https://forum.godotengine.org/uploads/default/original/3X/1/0/104a1121ae01b58c9e6e6c51413c13591850b5b1.gif)

So, I’m officially stumped here. As I understand it there is some weirdness involved with trying to manipulate a RigidBody’s position/rotation every frame, but I couldn’t figure out a different solution that worked within the constraints of the object type myself.

Through further testing I’ve been able to find that moving a RigidBody through its built-in force functions (impulse, torque, etc) seems to get the body to interact well with the ground, not clipping in like the second gif. But I can’t for the life of me figure out how to make that movement something the player can control in the way I want it to. I think the answer might have something to do with having a target position that the RigidBody always tries to move toward with a constant force? But that’s just a guess, and my tries there haven’t been to successful either.

Does anybody have any ideas? Have I been even a little close with any of my attempts? Please let me know if so!! Thank you so much :]

---

<div class="post-metadata">

**Author:** ![Snip\_Nineteen](https://forum.godotengine.org/user_avatar/forum.godotengine.org/snip_nineteen/32/58470_2.png) [@Snip\_Nineteen](https://forum.godotengine.org/u/Snip_Nineteen)\
**Post date:** [October 3, 2025, 8:35am UTC](https://forum.godotengine.org/t/need-help-manipulating-rigidbody2d-according-to-analog-stick/124025/2 "2025-10-03T08:35:59Z")

</div>

One final thing; It’s been suggested to me already that the setup in my last gif was the closest to correct, and I must now figure out how to manually create the physics interactions with the legs and the ground by applying opposite vector forces to the body. This illustration was provided for reference.

 ![1759393110-817745-image](https://forum.godotengine.org/uploads/default/original/3X/7/2/72725b35bd144d756f0e1dc70c255bb40eeb5305.png)

For this idea to work, I would need to be a skilled mathematician. I am not a skilled mathematician. If this is really the answer, then would anybody be willing to help me figure out the math there? Of course, if there is any simpler, non-math-centric solution, I’ll definitely take that instead!!

---

<div class="post-metadata">

**Author:** ![dragonforge-dev](https://forum.godotengine.org/user_avatar/forum.godotengine.org/dragonforge-dev/32/26042_2.png) [@dragonforge-dev](https://forum.godotengine.org/u/dragonforge-dev)\
**Post date:** [October 3, 2025, 2:28pm UTC](https://forum.godotengine.org/t/need-help-manipulating-rigidbody2d-according-to-analog-stick/124025/3 "2025-10-03T14:28:23Z")

</div>

I recommend using a **CharacterBody2D** and having both the circle and leg as part of that. It will then interact the way you want with other objects with less code.

Then, instead of mathing it, when the end of the leg collides, just move the pivot point of the whole thing to the end of the leg. Then back to the center of the circle. No idea how you’d do that TBH. You might need to use a **Polygon2D** instead of two separate shapes.

---

<div class="post-metadata">

**Author:** ![Snip\_Nineteen](https://forum.godotengine.org/user_avatar/forum.godotengine.org/snip_nineteen/32/58470_2.png) [@Snip\_Nineteen](https://forum.godotengine.org/u/Snip_Nineteen)\
**Post date:** [October 3, 2025, 6:30pm UTC](https://forum.godotengine.org/t/need-help-manipulating-rigidbody2d-according-to-analog-stick/124025/4 "2025-10-03T18:30:14Z")

</div>

Thank you, I’ll give that a shot :]

---

<div class="post-metadata">

**Author:** ![Snip\_Nineteen](https://forum.godotengine.org/user_avatar/forum.godotengine.org/snip_nineteen/32/58470_2.png) [@Snip\_Nineteen](https://forum.godotengine.org/u/Snip_Nineteen)\
**Post date:** [October 3, 2025, 8:58pm UTC](https://forum.godotengine.org/t/need-help-manipulating-rigidbody2d-according-to-analog-stick/124025/5 "2025-10-03T20:58:28Z")

</div>

Through some research I have found that it is unfortunately impossible to change the pivot point of a Node2D. You can set a temporary new pivot for scaling and such in the editor, but I think changing it in the actual game is literally not possible.

---

<div class="post-metadata">

**Author:** ![dragonforge-dev](https://forum.godotengine.org/user_avatar/forum.godotengine.org/dragonforge-dev/32/26042_2.png) [@dragonforge-dev](https://forum.godotengine.org/u/dragonforge-dev)\
**Post date:** [October 3, 2025, 9:03pm UTC](https://forum.godotengine.org/t/need-help-manipulating-rigidbody2d-according-to-analog-stick/124025/6 "2025-10-03T21:03:50Z")

</div>

I feel like I’ve done this, but I cannot remember how or what project it was in. Sorry the idea didn’t pan out.

---

<div class="post-metadata">

**Author:** ![Snip\_Nineteen](https://forum.godotengine.org/user_avatar/forum.godotengine.org/snip_nineteen/32/58470_2.png) [@Snip\_Nineteen](https://forum.godotengine.org/u/Snip_Nineteen)\
**Post date:** [October 4, 2025, 12:01am UTC](https://forum.godotengine.org/t/need-help-manipulating-rigidbody2d-according-to-analog-stick/124025/8 "2025-10-04T00:01:45Z")

</div>

Still need help with this. It’s basically the same movement concept as in the game “Getting Over It.” Has anyone ever succeeded in coding something similar to that in Godot? Please, the deadline for this project is in two weeks and I’ve been stuck on the basic movement for three days now. I’m starting to go insane here. Please help!!!

---

<div class="post-metadata">

**Author:** ![hyvernox](https://forum.godotengine.org/user_avatar/forum.godotengine.org/hyvernox/32/57242_2.png) [@hyvernox](https://forum.godotengine.org/u/hyvernox)\
**Post date:** [October 4, 2025, 2:03am UTC](https://forum.godotengine.org/t/need-help-manipulating-rigidbody2d-according-to-analog-stick/124025/9 "2025-10-04T02:03:02Z")

</div>

I’ve experimented a bit on this, and it’s probably not very clean, but it somewhat works:

- one Rigidbody2D with circle shape and locked rotation
- another Rigidbody2D (leg) **at the same position** with an offset capsule shape and center of mass set to (0, 0)
- a Pinjoint2D at the same position of both Rigidbody2Ds connecting them

The movement is done by changing the leg’s angular velocity and changing the offset of its collision shape. This is the leg’s script:

```gd
extends RigidBody2D

@export var rotation_speed := 5.0
@export var extension_speed := 100.0
@export var min_extension_length := 5.0
@export var max_extension_length := 30.0

@onready var leg := $CollisionShape2D

func _physics_process(delta: float) -> void:
	
	var vertical_input := Input.get_axis("ui_down", "ui_up")
	if vertical_input:
		var current_length :float = leg.position.y
		var target_length := current_length + extension_speed * vertical_input * delta
		target_length = clamp(target_length, min_extension_length, max_extension_length)
		leg.position.y = target_length

func _integrate_forces(state: PhysicsDirectBodyState2D) -> void:
	
	var horizontal_input := Input.get_axis("ui_left", "ui_right")
	angular_velocity = horizontal_input * rotation_speed

```

Changing the shape’s offset for this feels very inappropriate, but its better than nothing I guess.  
(The input needs some adaptation for an analog stick though. When taking all 4 directions, the shape’s offset could be set according to the input vector’s length. And the angular rotation can be modified depending on the angle between input vector and the legs current rotation.)

---

<div class="post-metadata">

**Author:** ![hyvernox](https://forum.godotengine.org/user_avatar/forum.godotengine.org/hyvernox/32/57242_2.png) [@hyvernox](https://forum.godotengine.org/u/hyvernox)\
**Post date:** [October 4, 2025, 3:07am UTC](https://forum.godotengine.org/t/need-help-manipulating-rigidbody2d-according-to-analog-stick/124025/10 "2025-10-04T03:07:10Z")

</div>

Didn’t got to test it with an analog stick myself (imitated its input from mouse cursor though) and something like that should do it:

```gd
extends RigidBody2D

@export var max_extension_length := 25.0

@onready var leg := $CollisionShape2D

func _physics_process(delta: float) -> void:
	
	var input_direction := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
	leg.position.y = max_extension_length * input_direction.length()

func _integrate_forces(state: PhysicsDirectBodyState2D) -> void:
	
	var input_direction := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
	var leg_direction :Vector2 = leg.global_position - global_position
	var angle = leg_direction.angle_to(input_direction)
	angular_velocity = angle / get_physics_process_delta_time()

```

The circle shape Rigidbody2D needs a much higher mass for these inputs, because the angular velocity gets way higher.

---

<div class="post-metadata">

**Author:** ![Snip\_Nineteen](https://forum.godotengine.org/user_avatar/forum.godotengine.org/snip_nineteen/32/58470_2.png) [@Snip\_Nineteen](https://forum.godotengine.org/u/Snip_Nineteen)\
**Post date:** [October 4, 2025, 6:54am UTC](https://forum.godotengine.org/t/need-help-manipulating-rigidbody2d-according-to-analog-stick/124025/11 "2025-10-04T06:54:21Z")

</div>

YOU ARE MY NEW FAVORITE PERSON.  
It works like a dream!!! Thank you so much, you just saved this project :]

---

<div class="post-metadata">

**Author:** ![system](https://forum.godotengine.org/uploads/default/original/2X/4/4b0a7fa8a6334634b94a13d421f0d99e6f04e21f.svg) [@system](https://forum.godotengine.org/u/system)\
**Post date:** [December 4, 2026, 10:03pm UTC](https://forum.godotengine.org/t/need-help-manipulating-rigidbody2d-according-to-analog-stick/124025/12 "2026-12-04T22:03:58Z")

</div>

Closed on December 4, 2026, 10:03pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
