Jump to content

[SOLVED] Problem to controlling a JointRail that captured from editor.


Recommended Posts

Hello!

I have a problem with received rail joint from scene in editor. I can get it but is possible to use only basic Joint class functions but no JointRail.

 

Example:

 

//globals

Node Wheelset[];
Node Rail[];
Body Wset_body[];
Body Rail_body[];

Joint Rail_joint[]; 

 

int init() {

 

    int index_of_wheelset = engine.editor.findNode ("wheelset_0");
    Wheelset[0] = engine.editor.getNode (index_of_wheelset);
 
    int index_of_rail = engine.editor.findNode ("rail_0");
    Rail[0] = engine.editor.getNode (index_of_rail);
 
    Wset_body[0] = Wheelset[0].getObjectBody();
    Rail_body[0] = Rail[0].getObjectBody();
 
    int index_of_joint = Wset_body[0].findJoint("railjoint of wheelset_0 # 0"); 
    Rail_joint[0] = Wset_body[0].getJoint(index_of_joint);
 
    Rail_joint[0].setEnabled(0); //That's ok, this method belongs to basic Joint class.
 
    ////Another call
    Rail_joint[0].setLinearVelocity(100); //That's not ok! It seems system not define this joint like JointRail but in scene it's created like this. If I evidently set it like JointRail in global variables - no one methods                                                                                    
                                                             //works. Editor shows a message: "can't find "class JointRail * __ptr64"...
    return 1;
}
 
How I can achieve my aim, get a joint rail from scene and freely control it? 
Thank's :) 

 

Link to comment

Of course it does not work since Body::getJoint() returns a basic Joint instance. And you try to call a method of JointRail. So what you need to do is simply cast Joint to JointRail.

Rail_joint[0] = Wset_body[0].getJoint(index_of_joint);

JointRail joint_rail = body_cast(Rail_joint[0]); // cast Joint to JointRail
joint_rail.setLinearVelocity(100);

 

Just a comment, if you didn't notice that (but I'm sure you did!):

Node Wheelset[]; // this is a map
Node Rail[0]; // this is a vector

 

 

Link to comment
×
×
  • Create New...