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.

DarkBASIC Discussion / What would be a good method to measure an object's trajectory?

Author
Message
Gilrad
17
Years of Service
User Offline
Joined: 29th Oct 2002
Location:
Posted: 30th Oct 2002 18:04
I have an idea for an Asteroids/Subspace-like game, but one thing I haven't the slightest clue on, is how to code the trajectory, so a ship can float in a direction, while turning, with any projectiles that would be fired reacting to the ship accordingly.

Now I'm not a math wiz, but I was thinking that maybe, in order to get the angle of the object's trajectory on a 2-d playing surface (although I will still use 3d because I could use it's collision detection), I could measure it in the form of a function, but then again the last time I touched raw code was with Qbasic, so I wouldn't know if there are any commands that would help me, or even do the entire job for me.
The Darthster
17
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 31st Oct 2002 01:21
Ok, floaty space physics.



If it's in space, you can remove the friction value completely, setting it to 1, but the ship will never slow down (on it's own). Since you have x and z velocities, you can fire missiles relative to the ship by adding the x and z velocities of the ship to the velocities of the missile. Plus you can do recoil by accelerating the ship in the opposite direction to the missile.

There are probably other ways to do this, but that's how I've done it.
Gilrad
17
Years of Service
User Offline
Joined: 29th Oct 2002
Location:
Posted: 31st Oct 2002 02:30
Actually, I was hoping for something more explanitory... Keep in mind that I am planning to expand on whatever method I decide on to also take into account what would happen if it would run into a wall, how it would bounce, ect.

Gilrad
17
Years of Service
User Offline
Joined: 29th Oct 2002
Location:
Posted: 1st Nov 2002 02:34
Actually, the more I look at it, the clearer it is, but the only part I still can't quite grasp is the usage of sine and cosine.

The Darthster
17
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 1st Nov 2002 21:27
The thruststep is the acceleration, i.e. how much the thrust will increase by each loop. The turnstep is how much the object will turn by each loop.

This code implements the controls based on these:



The thrust is multiplied by a number less than one so it reduces if the controls are untouched. The x and z velocities are multiplied by a friction value, between 0 and 1 where 1 is no friction and 0 is infinite friction.

The motion of the object is independent of the direction it is turning, so we need to use different variables. Since there is very little friction, the object will keep moving in the direction thrust is applied. Every time thrust is applied the object needs to move in the direction it is applied, so we add x and z components of the thrust to the x and z velocities. The sin and cos are just a way of working out how much thrust is applied in each direction.

If it were to bounce off a wall, for the sake of simplicity say a wall parallel to the xy plane, then the x velocity would be turned negative, and the ship would bounce off and travel in the other direction. To make some damping in the collision, instead of multiplying by -1, multiply by -0.5 or some number greater than -1 but less than 0.

Does that clear it up a bit?
Gilrad
17
Years of Service
User Offline
Joined: 29th Oct 2002
Location:
Posted: 2nd Nov 2002 01:40
Sorta, but most of that I found within these last few days. What I need help from, is when you try to make it bounce off walls that are't perpendicular, 90 degree angles.

What I am thinking, is that I multiply the x and z velocities by the sine and cosine of the angle the wall is (xvel=-1*sin(45), for instance), but it doesn't seem to be doing much.

Login to post a reply

Server time is: 2020-08-13 18:44:42
Your offset time is: 2020-08-13 18:44:42