Hello everyone, I'm currently working on a finite state machine for my enemy ai. One of the states i want to implement is a patrolling state. I want this to be the default state when the enemy spawns, so they patrol the given spawn area which is passed as a floatRect.
Now to do this, I figured i would make a randomly positioned floatrect, which is fine, but to get a random point inside the floatrect at which to spawn the enemy sprite i used the following method:
spawn = the name of the floatrect in question...
sf::Vector2f(float(rand() % (int(spawn.left) + int(spawn.width)) + int(spawn.left)),
float(rand() % (int(spawn.top) + int(spawn.height)) + int(spawn.top)));
Now i've tried various versions of casting to int and not casting to int, without any noticeable change. they need to be ints for rand() to work, and each number needs to also be cast back into a float to work with vector2f. i add the left to the width to get the global position of the far side of the rect, and then add the left side to the formula to make it so that rand() starts its range at the beginning of the rect and not at 0.
Either way, none of this is working and the sprites appear seemingly wherever they like.
can include more code if needs be, but for testing purposes all im doing is drawing them to the screen in the initial position contained in the above vector2f.
Thanks for your time.