Jump to content

[SOLVED] help for addForce


Recommended Posts

 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
  • 2 weeks later...

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
×
×
  • Create New...