Godot Version
4.3
Question
Hi! I ran into a problem: an item that the player picks up is rolling and dance to much. I want the object not to move at all in his hands, but I still haven’t figured out how to do it, please help!
here is the item code:
extends RigidBody2D
var picked = false
func _physics_process(delta: float):
if picked == true:
self.position = get_node(“…/player/Marker2D”).global_positionfunc _input(event: InputEvent):
if Input. is_action_just_pressed(“ui_pick”):
var bodies = $Area2D.get_overlapping_bodies()
for body in bodies:
if body.name == “player” and get_node(“…/player”). canPick == true:
picked = true
get_node(“…/player”). canPick = false
if Input.is_action_just_pressed(“ui_drop”) and picked == true:
picked = false
get_node(“…/player”).canPick = true
apply_impulse(Vector2(), Vector2(5,-5))
else:
apply_impulse(Vector2(), Vector2(-5,-5))
here is the player’s code (if its needs too):
extends CharacterBody2D
var canPick = true
@export var speed = 200.0
@export var jump_height = -400.0var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)
func _physics_process(delta):
if not is_on_floor():
velocity.y+= gravity * deltaif Input.is_action_just_pressed(“ui_accept”) and is_on_floor():
velocity.y = jump_heightvar direction = Input.get_axis(“ui_left”, “ui_right”)
if direction:
velocity.x = direction * speed
else:
velocity.x = move_toward(velocity.x, 0, speed)
Thank you so much!!