I have downloaded the demo Unity project from:
On top of this for POC for a physics game I am working on I am using Planck.ts
Here is my added code on main.ts in the server modules src folder
//Physics
function SimulatePhysicsMovement() : string {
let gravity = planck.Vec2(0.0, -10.0);
const world = new planck.World({
gravity: gravity
});
let ground: planck.Body;
let ball: planck.Body;
//Creating the cricket pitch
let groundDef = {
position: planck.Vec2(0.0, 0.0)
};
ground = world.createBody(groundDef);
let groundBox = planck.Box(10.0, 1.0);
ground.createFixture(groundBox, 0.0);
//Creating the cricket ball
ball = world.createBody({
type: "dynamic",
position: planck.Vec2(-20.0, 5.0)
});
let ballCircle = planck.Circle(0.35);
let ballFixtureDef = {
shape: ballCircle,
density: 1.0,
friction: 0.3
}
ball.createFixture(ballFixtureDef);
//Adding force to ball
ball.applyForce(planck.Vec2(5.0, 0), ball.getWorldCenter());
//Game Loop Calculation
let timeStep = 1/60;
let velocityIterations = 6;
let positionIterations = 2;
let allStates = "";
for(let i = 0; i < 60; i++){
world.step(timeStep, velocityIterations, positionIterations);
let position = ball.getPosition();
let angle = ball.getAngle();
console.log(position.x, position.y, angle);
allStates += `${position.x},${position.y}`;
}
return allStates;
}
const rpcPhysicsRenderPOC: nkruntime.RpcFunction =
function(ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, payload: string): string {
logger.info('Testing the calling of Physics RPC');
return SimulatePhysicsMovement();
}
I am registering it in the initialiser as:
initializer.registerRpc('physics_render_poc', rpcPhysicsRenderPOC);
Then from Unity Client I am accessing this as:
try
{
var response = await _connection.Client.RpcAsync(_connection.Session, "physics_render_poc", "");
Debug.Log("The Response from Physics POC RPC is: " + response.Payload);
}
catch (ApiResponseException e)
{
Debug.LogError("Couldn't get Physics Simulations: " + e.Message);
}
The Error response says:
Couldn’t get Physics Simulations: RPC function not found.
It seems to be according to the documentation only, not sure what I am doing wrong
NOTE: If I use any of the other RPCs which were present in the project, they are working…it is just the one I have added is not working