• Advertisement
Sign in to follow this  

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

This topic is 1269 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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(not rly)
Alright, instead of doing that I just did some geometry and rotated a point.
 
Edited by Ecoste

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement