vectorToAngle issues

jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
edited November -1 in Working with GS (Mac)
Is it possible to get an angle between two points, but relative to the actor not the scene? I've got a little guy, and i want him to be able to shoot upwards, but only 15 degrees from the top on each side.

the gameplay will be, touch to shoot to that position, if the angle between the guy and the destination is in the allowable area, shoot, otherwise do nothing.

if the guy is standing flat on the ground, this is easy, I can get the vector to angle of his position and the x position, and if that value is between 75 and 105, shoot. But my guy won't always be straight on the ground, he's rotating around a circle, so his base angle needs to adjust.

I tried using the rotation value to keep it calibrated, but that value keeps increasing the more the player rotates around the circle.

any ideas?

Comments

  • PhoticsPhotics Member Posts: 4,172
    I just got back from shoveling snow, so my thinking isn't the best for math right now, but did you try the modulo of 360?
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    i'm avoiding shoveling right now by looking at all the 25+ foot branches that keep falling all around our house :)

    i think that might work, it's at least got me moving in the right direction. thanks!
  • PhoticsPhotics Member Posts: 4,172
    Ha... days like this, Texas starts to look really good.

    Hm... Web Developer...
    http://gendaigames.com/careers/#job-wd
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    well, im going in circles. I can get the modulo of the angle I'm facing, and I can get the vector to angle of the center point, but im not sure how to join the two so the vector to angle altered depending on the rotation.

    time to go through the demos!
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    ok, this math is way above my head, anyone got any ideas?

    I've got a turret. it's only allowed to shoot +15 / -15 degrees from it's center point, but the entire thing could be pointing in any direction.

    Looking at the diagram below, I if I take a vector to angle of the center point to the valid target point (red), it'll come back something like 60 degrees, because it's based on 0 being "EAST" and 90 being "NORTH". I want the yellow line to be the "0, and the red lines to be +15 and -15 (or 345, whatever it has to be)

    but I may have 2 turrents pointing at different directions, so it has to be modular.

    can anyone help :)

    image
  • RHRH Member Posts: 1,079
    Wait, so am I right in thinking that you want to be able to calculate this angle:

    image

    when you know the red and yellow dots X and Y coordinates?
  • PhoticsPhotics Member Posts: 4,172
    Is it a turret on top of a tank?

    If you want to restrict the movement of the turret, then min/max might be a better way to go.

    The Pythagorean Theorem / vectorToAngle uses right angles. In your images, I don't see the use of right angles.
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    RH said:
    Wait, so am I right in thinking that you want to be able to calculate this angle:

    image

    when you know the red and yellow dots X and Y coordinates?

    yes, that's the angle i want, if possible. you'll tap to shoot, and i want to check the angle of the touch point and the center point, if it's less than 15 degrees, spawn a bullet, if it's over, don.t

    @Photics,

    not really, it's just the best way to describe what I want, each turret would be almost static, it could only move within the red lines, but the circle itself will never move.
  • RHRH Member Posts: 1,079
    Ok try this:

    constrain self.angle to: (vectorToAngle(( game.X - self.Position.X ),( game.Y - self.Position.Y ))) - self.rotation

    game.X. and game.Y are the red dots location, self.pos.X/Y are the turrets location.
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    that doesn't seem to work, i end up with negative values over relative to the X axis. this is very strange.
  • RHRH Member Posts: 1,079
    jonmulcahy said:
    that doesn't seem to work, i end up with negative values over relative to the X axis. this is very strange.

    Hmm, it works for me, I think. I'll upload a project and see if it's what you are after.
  • RHRH Member Posts: 1,079
    argh, I lost the project, can't get it to work again. I think it depends on how you rotate it. Here's a screen I had of how I set it up.

    image

    Both are constrain, the top one is self.angle2 and the bottom is the angle I highlighted in the image above.
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    arrggg!!! you were right, it works. I forgot that the start position of my actor is facing left, so rotation is technically at 180, I had to take my angles and add 180 to it, and then it worked.

    thank you so much
  • RHRH Member Posts: 1,079
    welcome :) glad it worked, was annoying me as well!
Sign In or Register to comment.