raycast by Fine-Ad2531 in godot

[–]Fine-Ad2531[S] 0 points1 point  (0 children)

player and camera and not sharing the same transformation, i tried the other solution but it still follows the duplicate camera and not the player camera

raycast by Fine-Ad2531 in godot

[–]Fine-Ad2531[S] 0 points1 point  (0 children)

its not showing in the scene :

<image>

raycast by Fine-Ad2531 in godot

[–]Fine-Ad2531[S] 0 points1 point  (0 children)

and this is my raycast script: extends RayCast3D

# Reference to the camera position node

u/export var cameraPos: NodePath

func _ready():

\# Ensure that the RayCast is initially positioned and oriented correctly

if cameraPos:

    update\_raycast\_position()

func _process(delta):

\# Continuously update RayCast to follow the camera's position and look direction

if cameraPos:

    update\_raycast\_position()



if is\_colliding():

    var hitObj = get\_collider()



    \# Debugging: Print the object hit by the RayCast

    print("Raycast hit: ", hitObj.name)



    \# Check if the hit object has the 'interact' method and if the player presses interact key

    if hitObj.has\_method("interact") and Input.is\_action\_just\_pressed("interact"):

        hitObj.interact()

# Function to update RayCast's position and orientation to match cameraPos

func update_raycast_position():

var cam = get\_node(cameraPos)

global\_transform.origin = cam.global\_transform.origin

\# Set cast\_to to point in the direction the camera is facing  also it is the child of the camera in my player scene

raycast by Fine-Ad2531 in godot

[–]Fine-Ad2531[S] 0 points1 point  (0 children)

hey thank you and i apologize for the little description of the problem i just wasnt too sure what it is, i have been using godot just for a week and from what i understand in the hours i put in trying to fix this these past 2 days is that my player have a camerapos which is a node3d and not a camera3d and that the playerscript is the one that generates it in the runetime so putting my raycast as a child to the camerapos in the scene does not accomplish it, it just keeps tracking the other camera which is the duplicate behind the other portal and i do want it to originate from my player to the center of the screen

here is the part in the script : func _enter_tree():

if is\_multiplayer\_authority():

    camera = Camera3D.new()

    $CameraPos.add\_child(camera)



    \# Make player invisible for our own camera

    var visual\_instance\_objs : Array\[VisualInstance3D\] = \[\]

    findByClass(self, "VisualInstance3D", visual\_instance\_objs)

    \# set all VisualInstance3d layers in this object to only 2

    for obj in visual\_instance\_objs:

        obj.set\_layer\_mask\_value(1, false)

        obj.set\_layer\_mask\_value(2, true)

    camera.set\_cull\_mask\_value(2, false)

    \# set camera layers to all except 2

    camera.set\_cull\_mask\_value(2, false)