I am currently attempting to code the Craig Reynolds Boids simulation. However, for the boids to maintain their behavior while avoiding obstacles, I need to be able to steer the boid away from the obstacle by a given angle. Is there any way of changing the angle of a 2D Vector by a certain angle theta ? There might be a quick way using pygame built-in functionality, but I cannot be sure since the website is currently down. However, any way that works (no matter time or space complexity) would be extremely helpful.
A pygame.math.Vector2
can be rotated with pygame.math.Vector2.rotate
or pygame.math.Vector2.rotate_ip
:
vec = pygame.math.Vector2(vx, vy)
rotated_vec = vec.rotate(degrees)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.