Re: Server Client bullet spawning

#14
Revive();
m_pEntity->GetNetEntity()->EnableDelegatableAspect(eEA_Physics, false);
m_pEntity->GetNetEntity()->BindToNetwork();
m_pEntity->GetNetEntity()->EnableAspect(kMovementAspect, true);-> missing



missing
struct RMI_NoParams
{
// In our example we will serialize a positional coordinate
Vec3 position;
Quat orientation; //!< Should translate to head orientation in the future

void SerializeWith(TSerialize ser)
{
// Serialize the position with the 'wrld' compression policy
// Serialize the orientation with the 'ori3' compression policy
ser.Value("position", position, 'wrld');
ser.Value("orientation", orientation, 'ori3');

}
};


// Only fire on press, not release
if (activationMode == eIS_Pressed)
{
//Calculate bullet position on client
if (ICharacterInstance* pCharacter = m_pAnimationComponent->GetCharacter())
{
IAttachment* pBarrelOutAttachment = pCharacter->GetIAttachmentManager()->GetInterfaceByName("barrel_out");

if (pBarrelOutAttachment != nullptr)
{
const QuatTS bulletOrigin = pBarrelOutAttachment->GetAttWorldAbsolute();

CryLog("Bullet spawn: x%f y%f z%f", bulletOrigin.t.x, bulletOrigin.t.y, bulletOrigin.t.z);
//Request server to spawn bullet

SRmi<RMI_WRAP(&CPlayerComponent::ServerFire)>::InvokeOnServer(this,
RMI_NoParams{bulletOrigin.t,bulletOrigin.q});



}
}
}



bool CPlayerComponent::ServerFire(RMI_NoParams && p, INetChannel* channel)
{
CRY_ASSERT(gEnv->bServer);

SEntitySpawnParams spawnParams;
spawnParams.pClass = gEnv->pEntitySystem->GetClassRegistry()->GetDefaultClass();
spawnParams.sName = "Bullet";
spawnParams.vPosition = p.position;
spawnParams.qRotation = p.orientation;
CryLog("Bullet spawn: x%f y%f z%f", bulletOrigin.t.x, bulletOrigin.t.y, bulletOrigin.t.z);

const float bulletScale = 0.05f;
spawnParams.vScale = Vec3(bulletScale);

// Spawn the entity
if (IEntity* pEntity = gEnv->pEntitySystem->SpawnEntity(spawnParams, false))
{
pEntity->GetNetEntity()->BindToNetwork();
auto spawnComponent = pEntity->CreateComponentClass<CBulletComponent>();
spawnComponent .velocity =p.rotation.Vector3()*1000;
gEnv->pEntitySystem->InitEntity(pEntity, spawnParams);
}


return true;
}
Last edited by mknmknmknjk on Tue Dec 18, 2018 4:20 pm, edited 3 times in total.

Re: Server Client bullet spawning

#16
Thanks for the help! I'm performing network binding when a client connects and accept bullet spawn position is not that good security wise. RMI structure is defined in another file, I probably should post the whole solution here.
The main problem, is that character skeleton is not getting loaded on the server and animations are not playing so, even if i fix bullet spawning that way, there still be collision issue.

Who is online

Users browsing this forum: No registered users and 2 guests

cron