Creating A Rope Entity in C++

#1
<Insert generic greeting here>

I am creating a system that places a rope between points in game. The ultimate problem I'm having is getting the rope to actually show.

Now I know the RopeEntity entity doesn't do anything (and if it does, its totally unclear and beyond complicated), so there's really no guide to follow to see if any of the code works.

Essentially, you place one point in the world, and place another and it connects the two points.

CODE BELOW

Code: Select all

void CRopeTest::CreateRope(Vec3 point1, Vec3 point2) { SEntityPhysicalizeParams physParams; SEntitySpawnParams spawnParams; pe_params_rope ropeParams; //Whats the difference? physParams.type = PE_ROPE; ropeParams.type = PE_ROPE; spawnParams.pClass = gEnv->pEntitySystem->GetClassRegistry()->GetDefaultClass(); ropeParams.length = 50; //fix this later. just figure out how to place the damn thing ropeParams.mass = 1; ropeParams.stiffness = -0.5f; //Theres more of these "point" things but one is a strided_ptr like wtf is that even? //dont bother googling ropeParams.ptTiedTo[1] = point1; ropeParams.ptTiedTo[2] = point2; IEntity *pRope = gEnv->pEntitySystem->SpawnEntity(spawnParams, true); //Physicalize Rope (if it exists) if (pRope != nullptr) { CryLog("This works"); //this usually works but the rope doesnt actually show wtf pRope->Physicalize(physParams); } else { CryLog("Damn"); } //Set Material auto *pRopeMaterial = gEnv->p3DEngine->GetMaterialManager()->LoadMaterial("Materials/Rope"); pRope->SetMaterial(pRopeMaterial); }
How is ropeParams.pPoints used? How do I actually create the two points and get the rope to be visible? Will there be anything more on this in 5.4?

Thanks for any answers!
-Moose
ImageTwitterImage

Re: Creating A Rope Entity in C++

#6
Alright, so here is the sample code for the rope. Set ropePt vec3 to whatever you need.

Code: Select all

SEntitySpawnParams spawn;
spawn.pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("RopeEntity");
spawn.nFlags = ENTITY_FLAG_CLIENT_ONLY;
spawn.sName = "Rope";
if (spawn.pClass)
{
pRope = gEnv->pEntitySystem->SpawnEntity(spawn);

pRope->SetFlags(pRope->GetFlags() | ENTITY_FLAG_CASTSHADOW);
IEntityRopeComponent *pRopeComponent = (IEntityRopeComponent *)pRope->CreateProxy(ENTITY_PROXY_ROPE);
if (pRopeComponent)
{
IRopeRenderNode *pRenderNode = pRopeComponent->GetRopeRenderNode();
if (pRenderNode)
{
//You can do more than 2 point if you wish
Vec3 ropePt[2];
ropePt[0] = point1;
ropePt[1] = point2;
//With these params it can act weird, but tweak them to match your expected behaviour
IRopeRenderNode::SRopeParams ropeParams;

ropeParams.nFlags = IRopeRenderNode::eRope_CheckCollisinos | IRopeRenderNode::eRope_Smooth;
ropeParams.fThickness = 0.05f;
ropeParams.fAnchorRadius = 0.1f;
ropeParams.nNumSegments = 12;
ropeParams.nNumSides = 4;
ropeParams.nMaxSubVtx = 3;
ropeParams.nPhysSegments = 12;
ropeParams.mass = 1.0f;
ropeParams.friction = 2;
ropeParams.frictionPull = 2;
ropeParams.wind = Vec3(0.0f, 0.0f, 0.0f);
ropeParams.windVariance = 0;
ropeParams.waterResistance = 0;
ropeParams.jointLimit = 0;
ropeParams.maxForce = 0;
ropeParams.airResistance = 0;
ropeParams.fTextureTileU = 1.0f;
ropeParams.fTextureTileV = 10.0f;
ropeParams.tension = 0.5f;

pRenderNode->SetParams(ropeParams);
pRenderNode->SetPoints(ropePt, 2);
}
}
}
Cryengine tutorial videos on my Youtube channel! Check it out !
https://www.youtube.com/user/MusicForLifePL20

Who is online

Users browsing this forum: No registered users and 1 guest