kai.tian2 Posted March 27, 2014 Share Posted March 27, 2014 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; } Link to comment
unclebob Posted April 7, 2014 Share Posted April 7, 2014 Hello Kai, That's happening because forces won't change velocities immediately. Use BodyRigid.addImpulse instead. Link to comment
kai.tian2 Posted April 10, 2014 Author Share Posted April 10, 2014 thank you unclebob i try addImpulse success . but i wan`t how to used addForce can you show me one Link to comment
kai.tian2 Posted April 10, 2014 Author Share Posted April 10, 2014 i find it first: bd.setShapeBased(0); bd.setMass(0.5); Second: flush() { bd.addForce(bd.getCenterOfMass(),vec3(0.0f,0.0f,5)); } this addforce must be Ten times that bd.getMass() Link to comment
Recommended Posts