我通过在static const CGFloat kPlayerMovementSpeed = 50.0f;
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch=[touches anyObject];
self.touchLocation=[touch locationInNode:self];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch=[touches anyObject];
self.touchLocation = location;
}
-(void)update:(CFTimeInterval)currentTime
{
if (itemHeld && refNode)
{
refNode.physicsBody.velocity=CGVectorMake(0, 0);
CGFloat distance = hypotf(refNode.position.x - self.touchLocation.x, refNode.position.y - self.touchLocation.y);
CGFloat damping = sqrt(distance * kPlayerMovementSpeed);
if (damping < 0)
{
damping = 0.0f;
}
refNode.physicsBody.linearDamping = damping;
refNode.physicsBody.angularDamping = damping;
CGPoint bodyPos = refNode.position;
CGPoint translation = CGPointMake(self.touchLocation.x - bodyPos.x, self.touchLocation.y - bodyPos.y);
CGVector velocityVector=CGVectorMake(translation.x * kPlayerMovementSpeed,
translation.y * kPlayerMovementSpeed);
refNode.physicsBody.velocity = velocityVector;
}
}
中改变它的速度来移动物理体。身体在移动,但这会产生一种不切实际的动作,因为它只是改变了它的位置,由于重力或空气摩擦,在抱着身体的点周围没有角度运动。在Apple开发人员指南中进一步了解物理机构的运动:
施加在身体上一点的力。物理模拟 计算身体角度和线速度的单独变化, 基于物体的形状和力的点 应用
关于如何通过施加力沿着身体上的触点实现角度运动的这种逼真运动的任何建议? 通过更新速度进行移动的当前代码:
$config['base_url'] = 'http://mysyite/folder/subfolder/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '';
$config['language'] = 'english';
$config['charset'] = 'UTF-8';
$config['enable_hooks'] = FALSE;
$config['subclass_prefix'] = 'MY_';
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd'; // experimental not currently in use
$config['log_threshold'] = 4;
$config['log_path'] = '';
$config['cache_path'] = '';
$config['rewrite_short_tags'] = FALSE;