Search the Community
Showing results for tags 'addforce'.
-
The problem with applying addForce() to PlayerActor.
evgenij.zherenkov posted a topic in C++ Programming
Hello! I apply force to the PlayerActor so that it moves horizontally. Logically, it should be uniformly accelerated (using gravity as an example), but its speed will fluctuate from 1.2-2. It seems as if something is stopping him from accelerating. In the vertical plane, everything works correctly. I use addForce() in the flush() function. And if I’m doing exactly the same but applying force to the created figures in maps, then everything works correctly. This effect is only in PlayerActor. PlayerActorPtr actor = PlayerActor::cast(Game::get()->getPlayer()); if (actor) { BodyRigidPtr obj = BodyRigid::cast(actor->getBody()); if (obj) { obj->addForce(obj->getCenterOfMass(), Math::vec3(0, 9.81f*obj->getMass(), 0)); } } -
i want use addForce() in flush() but is nothing happened #include <unigine.h> ObjectMesh mesh; BodyRigid bd; int jmp=false; Node addND(Node nd) { //node_remove(nd); nd.setName("abcd"); engine.editor.addNode(class_remove(nd)); log.message("add %s","==============================================="); return nd; //return node_remove(nd); } PlayerActor camera; ControlsDummy mycon=new ControlsDummy(); int init() { camera = new PlayerActor(); //Player camera=new PlayerDummy(); camera.setPosition(Vec3(0.0f,0.0f,2.5f)); camera.setDirection(Vec3(-1.0f,0.0f,-0.5f)); engine.game.setPlayer(camera); engine.controls.setStateKey(CONTROLS_STATE_JUMP,'f'); if(engine.editor.findNode("abcd")== -1){ log.message("NULL %s","========\r\n"); mesh=addND(new ObjectMesh("my_project/meshes/box.mesh")); mesh.setMaterial("mesh_noise_base","*"); mesh.setProperty("surface_base","*"); } else{ log.message("NOT NULL %s","========"); } Node dd= engine.editor.getNode(engine.editor.findNode("abcd")); Object ob=class_cast("Object",dd); bd=class_cast("BodyRigid",ob.getBody()); engine.controls.setKeyReleaseCallback("butt_ress"); return 1; } int shutdown() { return 1; } int update() { return 1; } int butt_ress(int button) { if(button==32) {//space log.message("body...... %s\n","space"); jmp=true; } return 0; } int xxcou=0; int flush() { if(jmp) { if(xxcou>1){ xxcou=0; jmp=false; } bd.setLinearDamping(0); bd.addForce(bd.getCenterOfMass(),vec3(0.0f,0.0f,10)); /* why this is noting happened */ xxcou++; log.message("flush...... %s\n","========================"); } return 1; }