chrisdill / raylib-cs

C# bindings for raylib, a simple and easy-to-use library to learn videogames programming

Home Page:http://www.raylib.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CameraPitch and CameraYaw don't allow passing a Camera3D as ref

leftbones opened this issue · comments

commented

Issue description

Since the built-in first person camera doesn't let you easily change things like speed, I was implementing it myself. I got movement working but when trying to implement camera rotation with the mouse, I found that CameraPitch() and CameraYaw() both require Camera3D* but attempting to pass in my Camera3D using ref gives the error:

Argument 1 may not be passed with the 'ref' keyword

Attempting to pass in the Camera normally (not ref) gives the error:

Argument 1: cannot convert from 'Raylib_cs.Camera3D' to 'Raylib_cs.Camera3D*'

So it appears there is no winning.

Environment

  • Windows 11
  • Raylib-cs 5.0.0
  • .NET 7.0.401

My game so far is a pretty barebones FPS, following the examples pretty closely. The only real difference is my Camera3D is stored as a property of the Player class. I'm not using any UpdateCamera or UpdateCameraPro methods, I'm performing my own movement calculations and applying them directly to Camera.position and Camera.target, which is working out fine.

Using UpdateCamera with the default first person camera stuff would be ideal, but I needed to be able to control the speed of the camera, which doesn't seem possible.

Can you pls show us your code?

grafik

This works for me?

So whats the problem?

Properties are not compatible with ref, thats basic C#.

@ChrisDill this issue could get closed.

grafik

This works for me?

My bad, I forgot that he mentioned properties, so what you could do is this:

  public class MyClass
  {
         private Camera3D _myCam = new(/*whatever here*/);

         public ref Camera3D => ref _myCam;
  }