c++ - Apply physics to player using bullet physics -


so i've had lot of problems trying physics applied play using bullet physics. i've tried kinematic bodies unsuccess. trying trying use rigid body i've had little successfully. pasted below updating code player's matrix , rigid bodies location. question how update player's position correctly.

update player's rigid body , camera's matrix *the gcamera.matrix projection , view matrix's multiplyed together

 physics.playerbody->getmotionstate()->getworldtransform(k); k.getopenglmatrix(glm::value_ptr(gcamera.matrix));  btvector3 j; j = physics.playerbody->getlinearvelocity();  gcamera.position.x = j.getx(); gcamera.position.y = j.gety(); gcamera.position.z = j.getz();   btvector3 pastpos; pastpos.setx(gcamera.position.x); pastpos.sety(gcamera.position.y); pastpos.setz(gcamera.position.z);  gcamera.getinput(window);   float lvelocityx = sin(gcamera.horizontalangle * 3.14159265359 / 180) * 2; float lvelocityy = physics.playerbody->getlinearvelocity().y(); float lvelocityz = cos(gcamera.verticalangle * 3.14159265359 / 180) * 2; //physics.playerbody->setlinearvelocity(btvector3(lvelocityx, lvelocityy, lvelocityz)); physics.playerbody->setlinearvelocity(btvector3(gcamera.position.x, gcamera.position.y, gcamera.position.z));  bttransform t; t.setfromopenglmatrix(glm::value_ptr(gcamera.matrix)); physics.playerbody->getmotionstate()->setworldtransform(t); physics.playerbody->setcenterofmasstransform(t); 

if want in control of player is, use kinematic. know you've had trouble that's best solution.

if want physics move player, need rigid body , apply forces move it.

it not possible move rigid body in reliable way. have had teleport objects in past have removed , added new rigid body, not want doing every frame player.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -