Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Odd object turning

Author
Message
tneva82
16
Years of Service
User Offline
Joined: 7th May 2008
Location:
Posted: 22nd Jan 2009 09:22
Alright. I'm programming simple top-down view spaceship shooting game(yeah not particulary inventive but start simple eh?-). Anyway things are shaping up. I have ship flying through space with asteroids(no collision detection yet. That's the next thing I will be adding along with guns.). However there's something seriously odd about the way ship is moving(and specifically turning). I'm trying to do it bit of Newton style(ie you can move one way and look the other). However if I press right and forward keys it's as if ship would be rotating around it's nose rather than in the middle. Also ship seems to be flying bit of odd at max speed(which I decided to implement against laws of physics so it wouldn't go all haywire. I call it safety protocol so that ship doesn't fly at uncontrollable speed!).

Anyway here's the relevant code snippets.

The one applying thrust so ship will move faster.



Here's the turning code:



And here's what loop calls to move the ship:



Anything I'm doing seriously wrong?
tneva82
16
Years of Service
User Offline
Joined: 7th May 2008
Location:
Posted: 22nd Jan 2009 10:05 Edited at: 22nd Jan 2009 11:55
Oh and I'm definetly doing SOMETHING wrong. Occassionally I manage to get into state where where when I'm pointing to direction 276(in angles) ie pretty much straight to left my heading is south-west(about 220 in angles). I push forward and it goes south west. I push backward and direction turns 180 to north-east. What am I doing wrong here?

Edit: I think I found this error atleast. It's the angleToRad table! Since GDK seems to use angles a lot I need them. Lots of trigonometric functions like sin etc however use radians so I need them as well so I made pre-generated table which contains radians for the angles where I can look them up as needed(faster than calculating on the fly). However there's some SERIOUS accuracy loss. Basicly radians change only at intervals of 60 degrees...What's wrong with my code?



Can't float handle 0.0xxx type of numbers?

Edit: Oh I COULD of course just check the darkGDK documents and note there's Sin and Cos functions that handle angles right there...Oops! Anyway so now it's working but if somebody could check the code anyway and see if I'm doing something wrong either in code or in my physics I would be grateful.

Edit2: More problems! Collision detection is way too early! Notable gap remains when it detects "collision". Any better ways to do it? ATM I'm doing it like this:



Called every time object is created.



And this is the one in main loop where I check wether ship has collided with asteroid.

So any better ways to compare wether they collided or not? Now is bit too close to make sense.
Matty H
16
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 22nd Jan 2009 15:36
I use sparkys and I think most other people do, Im not quite sure what is wrong with db collision but it definately has problems.
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 23rd Jan 2009 04:11
The float only goes to 7 places after the decimal. You could use a double...
tneva82
16
Years of Service
User Offline
Joined: 7th May 2008
Location:
Posted: 23rd Jan 2009 07:16
Quote: "The float only goes to 7 places after the decimal. You could use a double..."


0.01xxxx like this? Should be sufficient and anyway I tried double and didn't change a thing. However dbSin and dbCos do the trick so no need for any global array afterall.

Login to post a reply

Server time is: 2024-11-25 11:51:17
Your offset time is: 2024-11-25 11:51:17