tom.s Posted June 26, 2014 Share Posted June 26, 2014 Hi folks! I'm currently facing a rather annoying issue in Unigine, created by myself and my lack of understanding of course, which I need your help on! My situation is this: I have two characters, I want to calculate the mid-point between these two characters' heads and make a camera inside of the game look at that mid-point. What I am currently doing is: 1. Cycling through bones and finding the head bones of each character 2. Using ObjectMeshSkinned::getWorldBoneTransform to get the transform of each head bone as a mat4 3. Getting the 12th, 13th and 14th values from the head bone mat4s that represent the position of the head bones 4. Creating two separate vec3s for each head bone position using the values from stage 3 5. Finding the distance between the two values and normalising them to give me a look direction for my camera 6. Using Node::setDirection to set the direction the camera is facing like in the default setup of: camera = new PlayerSpectator(); camera.setDirection(Vec3(-1.0f, 0.0f, -0.5f)); The script I am using to get the PlayerSpectator from the world is: PlayerSpectator camera_Player = node_cast(engine.world.getnode(0123456789)); My problem is: When I try to do anything PlayerSpectator/Player/Node related with the PlayerSpectator variable I get an error saying: Project001/Project001.cpp: 1092: ExternClass::run_function(): can't find "class PlayerSpectator * __ptr64" base class in "class PlayerDummy" * __ptr64" class Can anyone suggest what I am doing wrong? Should I not node_cast cameras or something? Am I referencing them the wrong way? I can't even call Node::getNodeName or anything! Thanks in advance for your help! Tom Link to comment
helmut.bressler Posted June 27, 2014 Share Posted June 27, 2014 Hello Tom, I would guess that the node 0123456789 is a PlayerDummy and not a PlayerSpectator. Both PlayerDummy and PlayerSpectator are inheriting from the Player base class. If that is the case the following two lines should work: PlayerDummy camera_Player = node_cast(engine.world.getNode(0123456789)); Player camera_Player = node_cast(engine.world.getNode(0123456789)); However, if you need a PlayerSpectator and your world does not provide one you can also create your own in unigine script: PlayerSpectator camera = new PlayerSpectator(); engine.game.setPlayer(camera); cheers Helmut Link to comment
alterego Posted July 11, 2014 Share Posted July 11, 2014 Hello, Try using the attached code: void camera_look_at(Vec3 target) { Player camera = engine.game.getPlayer(); if(camera == NULL) { log.message(__FUNC__ + " : camera not found. \n"); return; } vec3 direction = normalize(vec3(target - camera.getWorldPosition())); camera.setDirection(direction); } Link to comment
Recommended Posts