Magnitude help?
JBULLFROG
Member Posts: 58
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.
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
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.
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.
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.)
Finding coordinates of a point in a circle with angle
to constrain the position of your tracker.
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.
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.
Ill try and play with it some more thanks.