0 votes

I was using some of the code from the docs. I was trying to get the location of the mouse. But when I ran the code I got an error. The error was Invalid get index 'position' (on base: float).

This is the code:

extends Camera

const ray_length = 10000

func _physics_process(event):
    var camera = $Camera
    var from = camera.project_ray_origin(event.position)
    var to = from + camera.project_ray_normal(event.position) * ray_length

It has no children. It is following a KinematicBody(3D). Godot_v3.1

in Engine by (27 points)

1 Answer

0 votes

Numbers don't have position properties. The parameter passed to _physics_process() is a floating point number, by default called delta. You've renamed it to event, but that doesn't change the fact that it will still be a number.

If you're talking about the tutorial here:
https://docs.godotengine.org/en/latest/tutorials/physics/ray-casting.html

That code uses the _input() function and checks if it was a mouse button click before casting the ray.

by (20,679 points)

Thank you. This helps!

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 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 webmaster@godotengine.org with your username.