const bool CharacterUpdaterPlayer::landPlayerOnTarget(const float distance, const float delta)
{
    // If we're not zoning in on our target
    if( distanceToPositionTarget == MAXFLOAT )
    {
        // Rotate towards our target first if we're pointing away from our target
        const float angleTowardsTarget = CCAngleTowards( player->getPosition(), positionTarget );
        const float angleDistance = CCDistanceBetweenAngles( player->rotation.y, angleTowardsTarget );
        if( angleDistance > 15.0f )
        {
            movePlayerRotation( positionTarget, delta );
            player->movementDirection.z = 0.0f;
        }
        else
        {
            distanceToPositionTarget = distance;
        }
    }

    // Now we are 100% rotated to our target
    else
    {
        if( distance <= distanceToPositionTarget )
        {
            distanceToPositionTarget = distance;
            player->movementDirection.z = -0.2f;
        }

        // As soon as we move past our target position, we know we've hit it
        else
        {
            CCObjectCollideable *collidedWith = CCBasicOctreeCollisionCheck( player, positionTarget, true );
            if( collidedWith == NULL )
            {
                player->setPosition( positionTarget );
            }
            player->movementDirection.z = 0.0f;
            moving = false;
            return true;
        }
    }
    return false;
}
Exemplo n.º 2
0
void CCPathFinderNetwork::connect()
{
    connectingNodes = true;

	removeFillerNodes();
	linkDistantNodes();

    // Reset our connections
	for( int i=0; i<nodes.length; ++i )
	{
		PathNode *node = nodes.list[i];
        CCList<PathNode::PathConnection> &connections = node->connections;
        connections.deleteObjects();
	}

	const float maxNodeDistance = CC_SQUARE( 200.0f );
	for( int i=0; i<nodes.length; ++i )
	{
		PathNode *currentNode = nodes.list[i];
        CCList<PathNode::PathConnection> &connections = currentNode->connections;

		for( int j=0; j<nodes.length; ++j )
		{
			const PathNode *targetNode = nodes.list[j];
			if( currentNode != targetNode )
			{
				const float distance = CCVector3Distance2D( currentNode->point, targetNode->point );
				if( distance < maxNodeDistance )
				{
                    const float angle = CCAngleTowards( currentNode->point, targetNode->point );

                    // Check to see if we already have this angle
                    //if( false )
                    {
                        int angleFoundIndex = -1;
                        for( int k=0; k<connections.length; ++k )
                        {
                            if( angle == connections.list[k]->angle )
                            {
                                angleFoundIndex = k;
                                break;
                            }
                        }

                        // We already have an angle connected closer
                        if( angleFoundIndex != -1 )
                        {
                            if( distance >= connections.list[angleFoundIndex]->distance )
                            {
                                continue;
                            }
                            else
                            {
                                PathNode::PathConnection *connection = connections.list[angleFoundIndex];
                                connections.remove( connection );
                                delete connection;
                            }
                        }
                    }

                    // Insert our node
                    PathNode::PathConnection *newConnection = new PathNode::PathConnection();
                    newConnection->distance = distance;
                    newConnection->angle = angle;
                    newConnection->node = targetNode;
                    connections.add( newConnection );
				}
			}
		}
	}

    connectingNodes = false;
}
const float CharacterUpdaterPlayer::movePlayerRotation(const CCVector3 &target, const float delta)
{
    const float angleTowardsTarget = CCAngleTowards( player->getPosition(), target );
    CCToRotation( player->rotation.y, angleTowardsTarget, delta * 720.0f );
    return angleTowardsTarget;
}