Jump to content

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


AquSe
 Share

Recommended Posts

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.rotation = lazorRadians;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.

  BkqvB.jpg
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(in another way)
Alright, instead of doing that I just did some geometry and rotated a point.
 
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...