Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [Q] Issues with Rotation and Movement: Super Simple AI  (Read 1055 times)

0 Members and 1 Guest are viewing this topic.

UchihaKite

  • Newbie
  • *
  • Posts: 33
    • View Profile
    • Email
[Q] Issues with Rotation and Movement: Super Simple AI
« on: September 20, 2016, 05:15:45 am »
Good evening once again fellow programmers!

Kite is here once again hoping to get some more education from the SFML community. Don't worry! This time it does have to do with SFML, at least more so than my usual questions.

Anyway! So, I am trying to develop a simple AI for my Asteroids Game. Basically, he is just going to fly around and follow the player, shoot at him when he is a certain distance away. The issue I am having though, is he will not rotate to face the player, and he just keeps moving forward.

Please believe me when I say this, I really did try to Google a solution to this, I did find a lot of great examples, however none of them helped me to solve this issue. This website:
http://www.pushbuttonreceivecode.com/blog/top-down-shoot-em-up-mechanics-part-1
Got me pretty close, however, it seems the AI just rotates like 45 degrees to the right, then to the left, repeatedly well moving upward. Attached to this are some pictures of my code, thought it might be a little easier to read thank typing it out here.

Thank you to anyone who checks out my code, and for anyone who helps me out. I am really excited to not only show this project to my teacher, but to post it up in the forums for everyone to check out!

Edit(Update:

I managed to fix the rotation issue, instead of using SetAngle(angle + 180 * dt), I used m_sprite.setRotation(toDegree(angle) + 90.f). And that seemed to solve it :D

The only issue I am having now is getting the enemy ship to actually move toward the player :/

Also, I noticed in my picture the if statement got cut off, so this is the full statement:

        if (m_sprite.getPosition().y >= playerLocation.y && m_sprite.getPosition().y < playerLocation.y + 720
                && m_sprite.getPosition().x >= playerLocation.x && m_sprite.getPosition().x < playerLocation.x + 720)
 

Edit(Update):
Whenever a Mod gets a chance, please remove this thread. I completely forgot when I was working on my AI that I already had methods to handle the movement and angles of all objects. So I was basically making a few calculations twice, and in two different ways. Which were all being executed lol Don't want to take up space for people who actually need help, I got it figured out. I posted a picture of the revised update function.
« Last Edit: September 20, 2016, 10:16:24 pm by UchihaKite »