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.

Author
Message
Thinker
14
Years of Service
User Offline
Joined: 4th Jan 2012
Location:
Posted: 5th Jan 2012 06:53
i am creating a space themed game but i need a script to operate the space ship speed.it will be in third person , i want the script to move a object at consistent speed until the w key is pressed where it increase speed over time. can any one give me a code that will make this work.
thanks

SpAs
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 5th Jan 2012 14:31 Edited at: 5th Jan 2012 14:40
Welcome to the community Thicker!

How much experience do you have using DBPRO?

There are a number of methods to make a spaceship fly; be it in 2D or 3D, but you may not understand the process if you have no experience with programming; which is not easy to tell with the information you have provided.

Let us know if you are creating a 2D or 3D game. The processes are similar in the sense that the position of your ship area represented as coordinates. In DBPRO we refer to these coordinates as X, for the horizontal (left to right) location; and Y for the vertical. When working in 3D, an additional dimension is used to represent the depth of a 3D location, which we called the Z axis.

Whether working in 2D or 3D, these positions can be accelerated using a speed, which is changed when a key is pressed. The DBPRO command; KeyState() can be used to detect if a key is pressed; if so, the speed can be changed. The movement alters the X,Y & Z locations by adding or subtracting the speed from them.

If you are new; there is a library of tutorials on this forum which you can visit here. You can also visit my banner at some point for additional tutorials after you have learned the basics.

Tutorial to look at: Beginners Tutorial

Commands to look for in the Help documentation in your DBPRO code editor include:
[3D]
Position Object, Move Object
[2D]
Sprite, MoveSprite

Here is a simple example of code that moves a sprite that you'd have to create


There are more ways to do this, and you would need to load your ship sprite; which is a 2D graphic. But based on the example and what you learn in the linked tutorial, you should be able to work out how to do more with your ship.

In 3D, you change the commands from Move Sprite to Move Object & Rotate Sprite Angle to Rotate Object X_Angle#, Y_Angle#, Z_Angle#. You do not need to work with 3 angles if your ship can only rotate left or right; in which case the commands Turn Object or YRotate Object can do the trick without worry about the other two angles.

You have some work making the camera follow the object; using the Set Camera To Follow command.

Link to Matrix1 utilities

Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 5th Jan 2012 14:39
@Chris Tate: "Welcome to the community Thicker!"
Lol, name fail!

My signature is NOT a moderator plaything! Stop changing it!
Millenium7
21
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 5th Jan 2012 16:00
Regardless of whether it's 2d or 3d you need to use several user defined values. I'd suggest



Using the 'type' command allows you to define multiple parameters for a value. In this case you can check PlayerShip.X to find the current X position, or PlayerShip.Velocity to find the current rate of travel and so on. Simplifies your labelling system a lot

You then simply write your loop to always update your ships X/Y/Z position according to the angle and velocity. When you press for instance the up key it will begin increasing the velocity by the .Acceleration stated per second until .MaxSpeed is reached. And if you press the down key it will decrease the velocity the same way

Boost may prove useful if you wish to incorporate an additional afterburner to increase your speed beyond the normal maximum speed. In which case you update position as before, with an additional amount stated by the current level of boost. Which most times would be 0 until you hit the afterburner

Make sense?

So if Ship.Y=100, the ship's angle is pointing directly upwards, and the current velocity is 50. Then Ship.Y will be 150 after 1 second, in order to make it be 150 after 1 second and not after 1 loop you incorporate
Timer1=timer()
into your main loop, just before the 'sync' command
Then when you are updating the ships position you write something like

inc Ship.Y, Ship.Velocity / (1000.0/(Timer()-Timer1))

It's late and my math might be wrong but I believe that would do. Basically it'll update by 50 divided by your frame rate. So if it's 60fps then you need to only update the speed by 0.8333 units per loop, since after 60 loops (which will be 1 full second) it'll end up being 50 units. If it's 10fps then it'll be 5 units per loop, and still 50 units per second of real time

Login to post a reply

Server time is: 2026-07-09 20:55:46
Your offset time is: 2026-07-09 20:55:46