How to get the SphereCollider and Rigidbody inside script

#1
Hie, I'm trying to port one of my asset from Unity3D to CryEngine and I have hit a silly problem. I need to access and interact with some of my components inside the script.

Here is my code in Unity3D

Code: Select all

public Rigidbody Rigidbody { get; set; } public SphereCollider SphereCollider { get; set; } . . . Rigidbody = GetComponent<Rigidbody>(); SphereCollider = GetComponent<SphereCollider>();
I have tried a similar approach in CryEngine since the component names are similar but I get errors. CryEngine can't pick those classes in my code. Here is my CryEngine code

Code: Select all

public Rigidbody Rigidbody { get; set; } public SphereCollider SphereCollider { get; set; } . . . SphereCollider = Entity.GetComponent<SphereCollider>(); Rigidbody = Entity.GetComponent<Rigidbody>();
How do I access my components.

Re: How to get the SphereCollider and Rigidbody inside script

#4
If you are coming from Unity then we have a nice documentation page to help you get started with the engine: https://docs.cryengine.com/display/CEMA ... From+Unity
It also contains a section on programming differences that you will likely find very helpful.

for your needs Entity.GetComponent just checks the entity that contains the component you are creating, therefore you will need to set up an entity in the scene with the component your making plus the components your looking for.
Alternatively you can create the component through code with Entity.CreateComponent or even do a mix using Entity.GetOrCreateComponent, this one will try and find the component on the entity first and if that fails it will then create a component for you. All that said just make sure you do this in the initialize as you likely only need it setup once

Re: How to get the SphereCollider and Rigidbody inside script

#5
I have managed to get the rigidbody by accessing the physics property of the entity as shown below.

Code: Select all

PhysicsEntity _physicsEntity = Entity.Physics;
But how do I access the sphere collider component attached to my entity?

Doing it this way is not working.

Code: Select all

SphereCollider _sphereCollider = Entity.GetComponent<SphereCollider>();
It says it can't find the type or name SphereCollider.

I'm thinking of downloading the PhysX sdk, maybe it's the sdk with the tools that I want since I have read it comes integrated with Unity and Unreal.

Who is online

Users browsing this forum: No registered users and 3 guests