Magnitude help?

JBULLFROGJBULLFROG Member Posts: 58
edited November -1 in Working with GS (Mac)
I have been trying to figure this out for a while now, so i figured I would ask for help.

I have my player center screen, and the enemies are spawned off screen at random points. What I would like to do is display an actor between the enemy and the player that tracks with the movement and constrained to the 480x320 screen. Of course once the enemy collides with this tracker I can have it destroy itself as now the enemy would now be on screen.

Ive read that

"Magnitude is the distance between two points.
A line segment if you will.

You would use it like this:

DistanceBetweenPlayerandEnemy = Magnitude(abs(PlayerX-EnemyX),abs(PlayerY-EnemyY))

(Magnitude is a measure of distance, and as such always needs to be positive. That is why the abs() method is in there as well)"

But Im not sure how this could help me if at all.

Comments

  • JBULLFROGJBULLFROG Member Posts: 58
    bump
  • JackBQuickJackBQuick Member Posts: 524
    Have a look at firemaplegames's Magnitude DEMO. I think it can do what you described. (You can download and open up the project to see how firemaplegames put it together.)
  • JBULLFROGJBULLFROG Member Posts: 58
    JackBQuick said:
    Have a look at firemaplegames's Magnitude DEMO. I think it can do what you described. (You can download and open up the project to see how firemaplegames put it together.)

    Yeah I took a look at that, although Its not exactly what I need to do. Honestly I'm not sure I even need to use magnitude, It just seemed like the right direction based no determining the distance between two objects.

    I guess I can explain it better. Player A is always center screen, and moving around based on your input. Enemy A is spawned off screen and starts moving towards Player A. As Enemy A approaches Player A and both actors are moving, I want an actor "Tracker" to appear at the edge of the screen, on a direct path/line between Enemy A and Player A. And if the Actors move the Tracker always stays between the two (Enemy A and Player A but "on screen") until Enemy A collides with Tracker as its trying to get to Player A.
  • JackBQuickJackBQuick Member Posts: 524
    Oops -- after thinking about this for a bit, firemaplegames's demo only allows you to track pre-existing actors, not spawned actors. Sorry.
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    Yes, you need magnitude. Its hard to explain if you dont have a understanding of it. I didnt really get it till it came up in college, i would search some math sites and get a good understanding of it. Cause magnitude will do what you want, you just need to know how to write you expression
  • JBULLFROGJBULLFROG Member Posts: 58
    JohnPapiomitis said:
    Yes, you need magnitude. Its hard to explain if you dont have a understanding of it. I didnt really get it till it came up in college, i would search some math sites and get a good understanding of it. Cause magnitude will do what you want, you just need to know how to write you expression

    Yeah I guess that's what I'm asking help with ;)

    ORBZ mentioned something on another post that seems like its close to what I was looking for.

    "BlockOffsetAngle = vectorToAngle(block.x - self.position.x, block.y - self.position.y)
    BlockDistance = magnitude(block.x - self.position.x, block.y - self.position.y)

    then use some trig to constrain the spawned object to the block:

    self.position.x = cos(BlockOffsetAngle) * BlockDistance
    self.position.y = sin(BlockOffsetAngle) * BlockDistance
    "

    What I did try was basically spawn an actor Tracker, at the same point that I spawned the Enemy, then set the tracker to move at a speed of 500 towards the Player, and then set a non-movable invisible actor on the stage slightly smaller then the 480x320, and set the tracker to bounce when it collides with this actor. This way I see which direction the tracker is coming from before the enemy arrives from that direction. This seems a bit ghetto and like a bad work around, plus the tracker moving at that speed (500) when it hits the wall I don't want it to bounce but press up against it, for some reason it blasts off the actor when it hits it.
  • JackBQuickJackBQuick Member Posts: 524
    You might also be able to use:

    Constrain To Circle DEMO

    Instead of constraining the blue ball to the mouse position, you can constrain it to Enemy A's position.

    And, you can use magnitude to measure the distance of Enemy A to the centre of the screen. When it comes within a certain distance, you can change the blue ball's alpha to zero (making it invisible).

    (I'm just brainstorming here -- I don't know whether this will work or whether you want something like this.)
  • JackBQuickJackBQuick Member Posts: 524
    Or, better yet, you can determine the angle of Enemy A (from center of screen) and then use

    Finding coordinates of a point in a circle with angle

    to constrain the position of your tracker.
  • JBULLFROGJBULLFROG Member Posts: 58
    JackBQuick said:
    Or, better yet, you can determine the angle of Enemy A (from center of screen) and then use

    Finding coordinates of a point in a circle with angle

    to constrain the position of your tracker.

    Thanks I'll look into those, and report back ;)
  • JackBQuickJackBQuick Member Posts: 524
    I was playing around and came up with this:

    radar

    (You can click and drag the blue ball.)

    I know it's not exactly what you want but it may give you some ideas.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    The problem is that it is difficult if not impossible to to constrain the X and Y coordinates of a spwaned actor to global attributes. What you may need to do is have all the actors in the scene at the beginning so you can constrain their X and Y to game attributes. Then recycle them instead of destroy them (just move them to a new offscreen spot when they are killed). All that constraining will probably cause problems though.

    Maybe you could constrain some large rectangular actors to the main player. And then set their Alpha to 0. Then have a rule that says when they overlap with a bad buy change alpha to .2. That way whn a bad guy gets close the actor will light up and you will know what direction the bad guy is coming from. Still a good deal of constrains but may be possible.

    good luck.
  • JBULLFROGJBULLFROG Member Posts: 58
    JackBQuick said:
    I was playing around and came up with this:

    radar

    (You can click and drag the blue ball.)

    I know it's not exactly what you want but it may give you some ideas.

    Thanks this is roughly what im looking for, although I cant figure out how to track several Target balls, and rather then it tracking in a circular pattern around the center, it would track in a square.

    Ill try and play with it some more thanks.
  • JackBQuickJackBQuick Member Posts: 524
    What scitunes wrote is true: too many constraints will cause you problems. You may want to investigate his suggestion:
    scitunes said:
    Maybe you could constrain some large rectangular actors to the main player. And then set their Alpha to 0. Then have a rule that says when they overlap with a bad buy change alpha to .2. That way whn a bad guy gets close the actor will light up and you will know what direction the bad guy is coming from. Still a good deal of constrains but may be possible.

    I think this may be the best solution.
Sign In or Register to comment.