Godot 4 C#: 3D Point and Click movement

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ต.ค. 2024
  • We're creating a point and click Navmesh movement.
    Socials:
    / royascoding
    www.facebook.c...

ความคิดเห็น • 21

  • @travisbarton4288
    @travisbarton4288 หลายเดือนก่อน +1

    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

    • @RoyasGodot
      @RoyasGodot  หลายเดือนก่อน +1

      Happy to help!

  • @juaman93
    @juaman93 7 หลายเดือนก่อน +1

    Hi Royas, cool video, thanks.
    What's the shortcut you used to rotate the DirectionalLight3D?

    • @RoyasGodot
      @RoyasGodot  7 หลายเดือนก่อน +2

      I used "e" to put myself into rotation mode then I clicked on the axis I wanted to rotate on. Hope this helps!

  • @AS_WovenLives
    @AS_WovenLives 3 หลายเดือนก่อน

    hiya, so i tried this out but the character just keeps going to the centre of the level when clicked.

    • @RoyasGodot
      @RoyasGodot  3 หลายเดือนก่อน

      Can you paste in the code so I can look it over? Thanks!

    • @AS_WovenLives
      @AS_WovenLives 3 หลายเดือนก่อน

      @@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;
      }
      }

    • @AS_WovenLives
      @AS_WovenLives 3 หลายเดือนก่อน

      @@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;
      }
      }

    • @AS_WovenLives
      @AS_WovenLives 3 หลายเดือนก่อน

      TH-cam keeps removing my comment when I try put the code here so I'm gonna reply in sections, sorry.

    • @AS_WovenLives
      @AS_WovenLives 3 หลายเดือนก่อน

      @@RoyasGodot
      using Godot;
      using System;
      public partial class PLAYER : RigidBody3D
      {
      Camera3D mainCam;
      NavigationAgent3D navAgent;
      public override void _Ready()

  • @GreasyOaf
    @GreasyOaf 3 หลายเดือนก่อน +1

    Can this be done in gd script

    • @RoyasGodot
      @RoyasGodot  2 หลายเดือนก่อน +1

      It can! I found a finepointCG video that teaches the concept well. th-cam.com/video/KT06pv06Q1U/w-d-xo.htmlsi=cE8XkImVTQrF3Vjd

    • @GreasyOaf
      @GreasyOaf 2 หลายเดือนก่อน

      @RoyasCoding I'll take a look! Thank you