@@RoyasGodot Code is below, when I click it just goes to the centre of the world. I'm unsure if it's thinking the mouse is in the centre and isn't actually finding the mouses location. ------------------ using Godot; using System; public partial class PLAYER : RigidBody3D { Camera3D mainCam; NavigationAgent3D navAgent; public override void _Ready() { mainCam = GetNode("Camera3D"); navAgent = GetNode("NavigationAgent3D"); navAgent.PathDesiredDistance = 0.5f; navAgent.TargetDesiredDistance = 0.5f; } public override void _Process(double delta) { if(Input.IsActionJustPressed("MouseClick")){ Vector3 from = mainCam.ProjectRayOrigin(GetViewport().GetMousePosition()); Vector3 to = from + mainCam.ProjectLocalRayNormal(GetViewport().GetMousePosition()) * 100; PhysicsRayQueryParameters3D rayQuery = new PhysicsRayQueryParameters3D(){ From = from, To = to }; PhysicsDirectSpaceState3D space = GetWorld3D().DirectSpaceState; Variant newVal; space.IntersectRay(rayQuery).TryGetValue("position", out newVal); navAgent.TargetPosition = (Vector3)newVal; } if(navAgent.IsNavigationFinished()){ LinearVelocity = Vector3.Zero; return; } Vector3 currentAgentPosition = GlobalTransform.Origin; Vector3 nextPath = navAgent.GetNextPathPosition(); LinearVelocity = currentAgentPosition.DirectionTo(nextPath) * 10; } }
@@RoyasGodot using Godot; using System; public partial class PLAYER : RigidBody3D { Camera3D mainCam; NavigationAgent3D navAgent; public override void _Ready()
you're a lifesaver! Trying to learn all this raycasting stuff AND translating to C Sharp from GD Script tutorials has been making my head spin! :S
Happy to help!
Hi Royas, cool video, thanks.
What's the shortcut you used to rotate the DirectionalLight3D?
I used "e" to put myself into rotation mode then I clicked on the axis I wanted to rotate on. Hope this helps!
hiya, so i tried this out but the character just keeps going to the centre of the level when clicked.
Can you paste in the code so I can look it over? Thanks!
@@RoyasGodot
Code is below, when I click it just goes to the centre of the world. I'm unsure if it's thinking the mouse is in the centre and isn't actually finding the mouses location.
------------------
using Godot;
using System;
public partial class PLAYER : RigidBody3D
{
Camera3D mainCam;
NavigationAgent3D navAgent;
public override void _Ready()
{
mainCam = GetNode("Camera3D");
navAgent = GetNode("NavigationAgent3D");
navAgent.PathDesiredDistance = 0.5f;
navAgent.TargetDesiredDistance = 0.5f;
}
public override void _Process(double delta)
{
if(Input.IsActionJustPressed("MouseClick")){
Vector3 from = mainCam.ProjectRayOrigin(GetViewport().GetMousePosition());
Vector3 to = from + mainCam.ProjectLocalRayNormal(GetViewport().GetMousePosition()) * 100;
PhysicsRayQueryParameters3D rayQuery = new PhysicsRayQueryParameters3D(){
From = from,
To = to
};
PhysicsDirectSpaceState3D space = GetWorld3D().DirectSpaceState;
Variant newVal;
space.IntersectRay(rayQuery).TryGetValue("position", out newVal);
navAgent.TargetPosition = (Vector3)newVal;
}
if(navAgent.IsNavigationFinished()){
LinearVelocity = Vector3.Zero;
return;
}
Vector3 currentAgentPosition = GlobalTransform.Origin;
Vector3 nextPath = navAgent.GetNextPathPosition();
LinearVelocity = currentAgentPosition.DirectionTo(nextPath) * 10;
}
}
@@RoyasGodot
Here's the code :)
Thankyou!
using Godot;
using System;
public partial class PLAYER : RigidBody3D
{
Camera3D mainCam;
NavigationAgent3D navAgent;
public override void _Ready()
{
mainCam = GetNode("Camera3D");
navAgent = GetNode("NavigationAgent3D");
navAgent.PathDesiredDistance = 0.5f;
navAgent.TargetDesiredDistance = 0.5f;
}
public override void _Process(double delta)
{
if(Input.IsActionJustPressed("MouseClick")){
Vector3 from = mainCam.ProjectRayOrigin(GetViewport().GetMousePosition());
Vector3 to = from + mainCam.ProjectLocalRayNormal(GetViewport().GetMousePosition()) * 100;
PhysicsRayQueryParameters3D rayQuery = new PhysicsRayQueryParameters3D(){
From = from,
To = to
};
PhysicsDirectSpaceState3D space = GetWorld3D().DirectSpaceState;
Variant newVal;
space.IntersectRay(rayQuery).TryGetValue("position", out newVal);
navAgent.TargetPosition = (Vector3)newVal;
}
if(navAgent.IsNavigationFinished()){
LinearVelocity = Vector3.Zero;
return;
}
Vector3 currentAgentPosition = GlobalTransform.Origin;
Vector3 nextPath = navAgent.GetNextPathPosition();
LinearVelocity = currentAgentPosition.DirectionTo(nextPath) * 10;
}
}
TH-cam keeps removing my comment when I try put the code here so I'm gonna reply in sections, sorry.
@@RoyasGodot
using Godot;
using System;
public partial class PLAYER : RigidBody3D
{
Camera3D mainCam;
NavigationAgent3D navAgent;
public override void _Ready()
Can this be done in gd script
It can! I found a finepointCG video that teaches the concept well. th-cam.com/video/KT06pv06Q1U/w-d-xo.htmlsi=cE8XkImVTQrF3Vjd
@RoyasCoding I'll take a look! Thank you