gaurdianAQ Member Posts: 106 From: Registered: 01-15-2007 |
I need to figure out a system to use so that I can move a ship like in asteroids where when you turn the ship it goes in the direction is facing preferably I would like it written in turing but if it can't then could you write it in BB and I will transfer it to turing | |
Mene-Mene Member Posts: 1398 From: Fort Wayne, IN, USA Registered: 10-23-2006 |
I can't find the thread, but thats what sine, and Cosine are. Beware, in Sine and Cosine the angle starts out at east so you'll need to subtact 90 from your angle so it would be something like this. BB:
------------------ I reserve the full right to change my views/theories at any time. [This message has been edited by Mene-Mene (edited February 23, 2007).] |
|
gaurdianAQ Member Posts: 106 From: Registered: 01-15-2007 |
that is how it was origanally being done but that caused to many problems using sine and cosine | |
Lava Member Posts: 1905 From: Registered: 01-26-2005 |
If it's top-down view (like astertoids), my advice would be to try making the value of which you move your character a varible, and make that varible be linked with the rotational values. Or make set values, so like if character rotation Y = 90 (however you find out how to measure the rotation) and move up, or wherever. But the set value way is too manual and would be very time consuming for a top-down game. Now it would work perfectly for a side-scrolling game, if you were making one. [This message has been edited by LAVA (edited March 04, 2007).] |
|
HanClinto Administrator Posts: 1828 From: Indiana Registered: 10-11-2004 |
I've programmed a number of top-down asteroids style space shooters, and I'm sorry to say, I've never found a good way to do it other than using sine and cosine. Mene's solution was in the right direction. Basically, you have to store a few things about your ship. Your coordinates (x and y values), your velocity (x and y values), and your heading (a single angle).
I'm just guessing at Blitz syntax from following Mene's example -- even though I'm sure it's wrong, I hope you get the basic gist of it. All the best, [This message has been edited by HanClinto (edited March 06, 2007).] |
|
jestermax Member Posts: 1064 From: Ontario, Canada Registered: 06-21-2006 |
try using a lookup table; do all your calculates when you load a level for each direction and store it in memory. then when you want to figure something out then just pass your direction to a function and it'll give you back your vectors. just an idea... | |
gaurdianAQ Member Posts: 106 From: Registered: 01-15-2007 |
well this is how I figured it out it uses a lot of code but it works much better and guess what I have decided to finish reading my game programming for teens book any ways here is how I did it in turingnow I know that looks ugly but it works a heck of a lot better |
|
dartsman Member Posts: 484 From: Queensland, Australia Registered: 03-16-2006 |
I used to do stuff like that when I first started it's a good learning curve though, when you step out of the basic 2d movement (if's and hard coded values) and then into angled movement (trig and time-based movement)... I'm glad that you posted this, shows you have real dedication and that you didn't just take an easier way out. I know you must have looked over and over the trig stuff and just now have moved to something which you are able to get done your own way, and you understand what it's doing keep on learning your doing pretty well in my opinion ------------------ |
|
gaurdianAQ Member Posts: 106 From: Registered: 01-15-2007 |
ty but actually I don't know trig I am only in grade 9. lol I copied the trig stuff from another program and then came up with my own system | |
gaurdianAQ Member Posts: 106 From: Registered: 01-15-2007 |
do you have any idea on how to make it so the bullet comes from the center of the ship with out having to add another 20 lines of code or am I going to have to do that? | |
jestermax Member Posts: 1064 From: Ontario, Canada Registered: 06-21-2006 |
instead of using the ship's x/y position use (pseudo-code): ship.x + ( ship.width / 2 ) |
|
Lazarus Member Posts: 1668 From: USA Registered: 06-06-2006 |
Hello. I'm working on a movement system similar to this one - but ran into some problems. In main loop: and in sub:
Looks fine, right - |
|
Mene-Mene Member Posts: 1398 From: Fort Wayne, IN, USA Registered: 10-23-2006 |
Laz: Couple of problems, 1. Don't you mean to say that: ship1.xVel = ship1.xVel + COS(ship1.heading-90) * thrust 2. Sine is for Y, Cosine for X: ------------------ I reserve the full right to change my views/theories at any time. |
|
HanClinto Administrator Posts: 1828 From: Indiana Registered: 10-11-2004 |
Hey Laz!
quote: In what units are you storing your ship's heading? Radians or degrees? Most computer programming languages use radians (where there are 2*pi of them in a circle) as opposed to degrees (where there are 360 of them in a circle). Here's a decent page that shows how degrees and radians line up. To convert from degrees to radians, multiply by (pi / 180). That would make your code look like the following:
Give that a whirl, and see how it works for you. To optimize it, you'd want to remove the division operation, and so the 3.14159 / 180 would turn into just 0.0174533, but I just left it that way so that you could see the theory behind it. Hope that helps! --clint [This message has been edited by HanClinto (edited March 28, 2007).] |
|
Lazarus Member Posts: 1668 From: USA Registered: 06-06-2006 |
Hey, thanks for the replies, guys! Clint, GLBasic uses degrees for the sin-cos-tan functions(a pleasant surprise - most Basics seem to use radians), so that part was working correctly. Mene, you hit on it - I reversed the sin-cos function calls, and it works perfectly. Sine for Y, Cosine for X. *slaps forehead* |
|
Mene-Mene Member Posts: 1398 From: Fort Wayne, IN, USA Registered: 10-23-2006 |
Laz: I'm so glad I could help, really I am. I've been constantly helped here, and glad I could return a little bit of ... ------------------ I reserve the full right to change my views/theories at any time. |
|
Lazarus Member Posts: 1668 From: USA Registered: 06-06-2006 |
Glad to hear it, because I've got another question. In this game - which is a Kspaceduel clone - the ship fires bullets(no surprise there). I worked out firing one bullet at a time - as shown below:
I'd like to be able to create another bullet each time the cannon is fired and have it move off in whichever direction, but - seems like I'd have to |
|
Lazarus Member Posts: 1668 From: USA Registered: 06-06-2006 |
K, nvm - I found a solution. |