I am passing player to controller by reference like so:
pub const Game = struct {
const Self = @This();
allocator: std.mem.Allocator,
camera: rl.Camera3D,
player: Player,
asteroid: Asteroid,
controller: Controller,
pub fn init(allocator: std.mem.Allocator) !Self {
var player = try Player.init(allocator);
return Self{
.allocator = allocator,
.camera = initCamera(),
.player = player,
.asteroid = Asteroid.init(),
.controller = Controller.init(&player),
};
}
But I am unable to modify some of player's fields namely it's velocity:
const std = @import("std");
const rl = @import("raylib");
pub const Player = struct {
const Self = @This();
allocator: std.mem.Allocator,
model: rl.Model,
position: rl.Vector3,
rotation: rl.Vector3,
velocity: rl.Vector3,
pub fn init(allocator: std.mem.Allocator) !Self {
const mesh = try initMesh(allocator);
return Self{
.allocator = allocator,
.model = rl.LoadModelFromMesh(mesh),
.position = rl.Vector3.zero(),
.rotation = rl.Vector3.zero(),
.velocity = rl.Vector3.zero(),
};
}
In controller: