AquSe Posted August 2, 2014 Share Posted August 2, 2014 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. 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. More can be found here. http://stackoverflow.com/questions/12161277/how-to-rotate-a-vertex-around-a-certain-point Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.