Ok let me see if I can walk through this
I have a sprite 3d on a kinetic body for a character, and turn it using rotate, so the front and back are always the same. I'm looking at the documentation to figure out how 2d and 3d works (sometimes in Godot it seems like you can ONLY use the 3d version, but it's not always clear in my opinion) For instance, I was able to use a Vector2 in my 3D to detect my x/z movement, and put my y movement on jump/gravity, then create a vector3 from them together to make the move_and_slide()
https://docs.godotengine.org/en/stable/tutorials/physics/ray-casting.html
So for 3D i'm looking at :
func _physics_process(delta):
var space_state = get_world().direct_space_state
I literally create a spatial>raycast
and I can move it around, is it simply the external box? Do i need to shrink it?
I can enable it, exclude parent (seems a good idea, then I should attach this ray to the foot collider I have?) and collide with bodies and areas (bodies being kinetic bodies and areas is collision shapes?)
Then I put "cast to" 0.15, 0 , 0 and I have a small single line
So, this is the correct 3d node, but ray casts are still simply single lines, correct? You need to set every angle you want? I take it for 3d things, people create a bunch of them on the fly in code?
For what I'm using, I'm thinking a single ray on the feet, that extend just slightly in front of my feet, would be best. Then I attach a script,
Now, I see in the example Godot page this script:
func _physics_process(delta):
var space_state = get_world_2d().direct_space_state
use global coordinates, not local to node
var result = space_state.intersect_ray(Vector2(0, 0), Vector2(50, 100))
This is the 2d rather than 3d, but it also seems to be creating a new ray, with the (Vector2(0, 0), Vector2(50, 100)) This is creating a ray at the GLOBAL space of 0,0 to 50,100 in 2D, correct?
So if I have a static ray created that follows my player, I just need something like this:
func _physics_process(delta):
var space_state = get_world().direct_space_state #this calls the current ray it's attached to?
if result:
print("Hit at point: ", result.position) #this means it hit something in 3d space?
Now, if I want to detect if it's a low, medium, or tall object, would I need 3 seperate ray casts?
Attach one slightly above the feet, for stuff to just step over? I saw that others just use a capsule collider with a round bottom, and it slides over if it's not to tall?
Attach one at the knees and use it like "steps"
and attach one at the chest and use it like "climb over"
Is there a way I can have all 3 on one script, so they don't interact with each other? Because if it hits the chest, it probably hits the knees and feet too.
Should I create 3 rays in the editor, and call them seperately in one script? Or attach a script that creates 3 rays? Or create 3 rays in my character's physics section where I have my movement script?
Sorry I'm rambling as I'm going through this myself, biggest questions:
Is my understanding correct, that the best way to put 3 rays into my character script (which is on the spatial node containing sprite 3d, colliders, etc), extending just slightly in front of me?
Or should I place the 3 colliders in the editor and call them?
If the first solution, how do I call a ray and place it on my kinetic body instead of the global position?
something like :
var raychest = self.intersect_ray(Vector2(0, 2), Vector2(2, 1))
var rayknee = self.intersect_ray(Vector2(0, 1), Vector2(1, 1))
var rayfeet = self.intersect_ray(Vector2(0, 0), Vector2(0, 1))
then script it out:
if raychest == true:
#climb over animation
if rayknee == true and raychest == false:
#step up animation
if rayfeet = true and raychest == false and rayknee == false:
#just step over object