When i move the camera too fast, the object falls

Godot Version

4.4.1

Question

Somebody knows how to fix it?
idk if the problem is the raycast or the frame rate.

my code:
extends Node

@onready var ray_cast = $“../Head/Headcam/RayCast3D”
@onready var marker_3D = $“../Head/Headcam/Marker3D”

func _physics_process(delta: float) → void:
var object = ray_cast.get_collider()
if ray_cast.is_colliding():
if object.is_in_group(“PICK”):
if Input.is_action_pressed(“primary”):

				object.global_transform.origin = marker_3D.global_transform.origin
				object.collision_layer = 2
				object.linear_velocity = Vector3(0.1,3,0.1)

When posting code, please use the preformatted text (</>) tool, or do:

```gdscript
code
code
code
```

That will get you:

code
code
code

You have:

extends Node

@onready var ray_cast = $“../Head/Headcam/RayCast3D”
@onready var marker_3D = $“../Head/Headcam/Marker3D”

func _physics_process(delta: float) → void:
    var object = ray_cast.get_collider()
    if ray_cast.is_colliding():
        if object.is_in_group(“PICK”):
            if Input.is_action_pressed(“primary”):
                object.global_transform.origin = marker_3D.global_transform.origin
                object.collision_layer = 2
                object.linear_velocity = Vector3(0.1,3,0.1)

A vector of (0.1, 3.0, 0.1) is going to be “downwards” unless the object has been rotated.

What are you trying to make this do? What is it doing instead?

Hey first thing thank u for ur help!

i just wanted to make an easy way to be able to pick up props, firstly it seems to work but when i shake the camera to much, the object falls down even though the input is pressed.

Ah, ok.

Usually in a situation like this, what you want to do is detect that an object has been picked up, and then attach it to the thing carrying it. Once you’ve attached, you don’t need to check for collision any more, and you don’t run the risk that some ordering problem in the physics calculations results in your raycast firing off to the side and not hitting the object.

I think what’s happening is that when you shake the camera, the raycast sometimes misses the thing you’re carrying, so it stops carrying it. Remember, the physics gets done in timesliced snapshots.

1 Like

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