Blog week 1 – Projectile shooting

Blog picture 1

Hi!
The whole prototyping has been rough, not becuase it was hard but more lack of time. And by lack of time i do not mean that we had little time but our group prioritised the wrong thig, since writing everything in main seemed wrong so we started to build an engine.

However we started prototyping and I’ve done so the character can shoot and aim with the mouse, however its a bit strange right now since its flying all over where i do not want it to be. I’ve yet to figure out a good way for the arrow to move exactly thowars the possition of the mouse.

I have a way to calculate the angle that is between the character and the mouse now i only need a way to draw a ”line” and make the arrow move according to it. But right now the arrow flies off somewhere mostly upwards of to the left, however it stays on the screen and does not travel out from it, no clue why. Never gotten it to fly to the right for now, but I can’t really continue unless im getting this correct.

Before I tried the angle calculation I though that maybe a way to use linear equation with Y = kx + m so i calculated delta X and delta Y and divided to get k and let the Y possition of the arrow be influenced by the x possition and only let it move right or left. The idea was good but in initiation it did not work, how do i know that? Well there where three possitions the arrow could be in, one in the top right, one in the middle top and the last was  in the top left. So i gave up on the idea of that, maybe i could have gotten it to work with enough time but i felt it was a hard and painfull way.

After that i started with the other way of doing it, I already had both delta X and Y so i could start from there, and in c++ there is a thing called atan2 wich could be used as a way to calculate angle so i took atan2(delta X, delta Y) / 180 * PI and this is really where I am at right now, trying to figure out a way to make it shoot to the point of the mouse.

Blog week 1 – Projectile shooting

2 reaktioner på ”Blog week 1 – Projectile shooting

  1. This post is pretty good at describing what you did and how you did it and has some value in explaining how not to do. However it sin’t totally clear about why you chose to do like you did. For example when you described that you used the linear equation you describe what it is and how you use it but i didn’t get why you chose to use it. It would have sufficed with something like: ”/…/since i thought that the linear equation would get the the right coordinates /…/” or just explain that it was a test to see if it worked.

    There is also some spelling and grammatical errors like the first sentence and the last one in the second part. Other than correcting the errors, you should also update the post with your solution to the problem that explains how you solved it so that others can take part of that knowledge.

    You have a pretty clear language and it’s nice to read since it isn’t very formal which is nice to read. Your explanations aren’t to complicated so it’s easy to take part of what you explained and i think that you can go a bit deeper to explain when if you want to explain more things a bit more thoroughly.

    Gilla

  2. I’m making another comment to try and explain how i got some angles to work.
    sf::Vector2i mousePosition = sf::Mouse::getPosition(*Window);
    Angle = atan2(mousePosition.y – ObjectPositionY , mousePosition.x – ObjectPositionX);

    This will give you an angle in radians that can be converted to degrees by using:
    Angle * 180 / M_PI

    Use math.h to get M_PI

    when you want to move the object I use :
    float cosine = cos(m_fAngle);// Note: This angle is in radians.
    float sine = sin(m_fAngle);
    m_pxSprite.setPosition(sf::Vector2f( ObjectPositionX+= cosine * VelocityX , ObjectPositionY += sine * VelocityY ));
    //Note:It’s probably better with a singel velocity.

    Gilla

Lämna en kommentar