/*virtual*/ bool RotateTowardsBehavior::Update(float dt, MovingObject* toUpdate, SGD::Point wayPoint)
{


	// Vector from Object to its Waypoint
	SGD::Vector toWaypoint = wayPoint - toUpdate->GetPosition();

	toWaypoint.Normalize();
	if (toWaypoint.ComputeDotProduct(toUpdate->GetDirection()) < 0.999f)
	{
		if (toUpdate->GetDirection().ComputeSteering(toWaypoint) > 0)
			toUpdate->SetRotation(toUpdate->GetRotation() + (SGD::PI * 0.15f * dt)); //Turn left
		

		else if (toUpdate->GetDirection().ComputeSteering(toWaypoint) < 0)
			toUpdate->SetRotation(toUpdate->GetRotation() - (SGD::PI * 0.15f * dt)); //Turn right

		SGD::Vector orientation = { 0, -1 };
		orientation.Rotate(toUpdate->GetRotation());
		toUpdate->SetDirection(orientation);
		return false;
	}

	return true;

}
Ejemplo n.º 2
0
void CPush::HandleCollision(IEntity* other)
{
	if (other == owner)
		return;
	SGD::Vector forward = {0,-1};
	forward.Rotate(rotation);
	SGD::Vector dir = other->GetPosition() - position;
	dir.Normalize();
	float angleBetween = dir.ComputeAngle(forward);
	if (radius < dir.ComputeAngle(forward))
	{
		return;
	}
	if (radius < SGD::PI * 2)
		dir.Rotate(angleBetween / 2);

	//float mass = other->GetSize().width * other->GetSize().height;
	other->AddGravity(dir * strength);
}
/*virtual*/ bool AlertBehavior::Update(float dt, MovingObject* toUpdate, SGD::Point wayPoint)
{
	// Vector from Object to its Waypoint
	SGD::Vector toWaypoint = wayPoint - toUpdate->GetPosition();

	if (toWaypoint.ComputeLength() < 32)
	{
		return true;
	}
	else
	{
		if (toWaypoint.ComputeLength() < 400.0f)
		{
			if (toUpdate->UpdateAttackTime(dt))
				toUpdate->Attack();
		}
		toWaypoint.Normalize();
		if (toWaypoint.ComputeDotProduct(toUpdate->GetDirection()) < 0.999f)
		{
			if (toUpdate->GetDirection().ComputeSteering(toWaypoint) > 0)
				toUpdate->SetRotation(toUpdate->GetRotation() + (SGD::PI  * dt)); //Turn left
			else if (toUpdate->GetDirection().ComputeSteering(toWaypoint) < 0)
				toUpdate->SetRotation(toUpdate->GetRotation() - (SGD::PI * dt)); //Turn right

			SGD::Vector orientation = { 0, -1 };
			orientation.Rotate(toUpdate->GetRotation());
			toUpdate->SetDirection(orientation);

			SGD::Vector newVelocity = orientation * toUpdate->GetMoveSpeed() * 1.75f;

			toUpdate->SetVelocity(newVelocity);
		}
		return false;
	}




}