View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Calculating co-ordinates of a line/ray that's increasing in height with a known slope/radians. Height increase is also known

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

No replies to this topic

### #1Ecoste  Members

Posted 02 August 2014 - 05:53 AM

basically in my game I'm firing a line. The line's anchor point is at the very bottom of it, and half of its width.

When I fire the line, its rotation gets set to face where we want it to go. Then, with each frame of the game, the height of the line increases and it looks like the player is firing a laser.

Here's the code for the initial setting-up to fire and later move the laser. Javascript, using PIXIJS.

    function fireLazor(mouseData){
firing = true;
slopeY = (player.y - mouseData.global.y) / (player.x - mouseData.global.x);
slopeX = (player.x - mouseData.global.x) / (player.y - mouseData.global.y);

lazor.x = player.x;
lazor.y = player.y;
}

Alright, now that the laser is set to go all we need to do is increase its height and it will go in the direction we set it to go.

if(firing){
lazor.height += lazorAcceleration * DELTA_TIME;
}

Now, that all works fine and dandy. Here's a visual to help.

I first wrote some code to basically check the whole path of the laser and see if it hits something, IN ONE FRAME. It works perfectly, but it does so in one frame and the second we fire the laser. And obviously I need for it to check gradually as the laser travels.

The problem comes in when we want to collision check the front of the lazor to see if it hit something. We need to figure out what the co-ordinates of the front of the laser are. So, I thought that if we know the slope and the rate at which the height is increasing we can just do(simplified example that would run each frame, except of course without resetting the xtocheck and ytocheck to the player co-ordinates.)

    ticks = lazorAcceleration / slopeY;
xToCheckForCollsion = player.x;
yToCheckForCollsion = player.y;

for(i = 0; i < ticks; i++){
xToCheckForCollsion += 1;
yToCheckForCollsion += slopeY;
}

I've tried multiplying, diving, both slopeY and slopeX, and other things I could possibly think of. Multiplying by delta time in different spots, ceiling and flooring, just don't know how else to twist it.

But, that doesn't work. The collision checks sometimes get ahead of the laser, sometimes they get behind it and etc.

Does anybody know how to get the front-coordinate of the laser? Or maybe even do this whole thing another way, I don't know.

Thanks!

SOLVED(not rly)
Alright, instead of doing that I just did some geometry and rotated a point.

Edited by Ecoste, 02 August 2014 - 08:14 AM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.