Try to drag sprite with touch move but its not working please help .
here
cocos2d::PhysicsSprite3D * sprite_apple;
Touch* touch = touches[0];
if(sprite_apple)
{
Vec3 pos;
pos.x = sprite_appleDumy->getPosition3D().x+touch->getDelta().x;
pos.y = sprite_appleDumy->getPosition3D().y+touch->getDelta().y;
pos.z = sprite_appleDumy->getPosition3D().z;
sprite_appleDumy->setPosition3D(pos);
}
its not working to me
Hey! Try to add this:
sprite_appleDumy->syncNodeToPhysics();
You should convert touch Point (on 2D ) to 3D.
Point loc = touch->getLocation();
Point prev = loc - touch->getDelta();
//convert 2D Point to 3D point with the Z
Vec3 p1 = unProjectGL(prev, z);
Vec3 p2 = unProjectGL(loc, z);
Vec3 delta = p2 - p1
//and then move your sprite with this 3D-delta
....
Vec3 HelloWorld::unProjectGL(Point p, float z)
{
Vec3 near = Vec3(p.x, p.y, 0);
Vec3 far = Vec3(p.x, p.y, 1);
Vec3 n = _camera->unprojectGL(near);
Vec3 f = _camera->unprojectGL(far);
float x0 = n.x;
float y0 = n.y;
float z0 = n.z;
float x1 = f.x;
float y1 = f.y;
float z1 = f.z;
float x = (((z - z0)/(z1 - z0))*(x1-x0)) + x0;
float y = (((z - z0)/(z1 - z0))*(y1-y0)) + y0;
return Vec3(x, y, z);
}
thanks @doanhieuthien.
Your logic help me a lot.