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.

Newcomers DBPro Corner / I turned my top down shooter into a turret game

Author
Message
Zaibatsu
18
Years of Service
User Offline
Joined: 1st May 2006
Location: Lost in Thought
Posted: 17th Jan 2009 23:37 Edited at: 17th Jan 2009 23:38
Seeing as how I was having trouble getting both moving AND aiming implemented in my last project, and the thread sunk down quite a ways, I've decided to make it easier. I've turned the player into a stationary turret in the center of the screen.

So I'm trying to implement shooting now, using the FPS tutorial by RUCCUS as a reference. I've used his code
and I get the following error:

.

Now I'll admit I have absolutely no idea how to use a limb, but from what I've read, it seems like it should work.

My current code is:



I've attached the media for anyone who didn't get it from the last thread.

Thank you for any help you may be able to provide,
Brett Snow

Attachments

Login to view attachments
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 17th Jan 2009 23:57 Edited at: 18th Jan 2009 00:00
The error you've posted means that you're not adding limbs in the correct order, i.e you have to go 1, then 2, then 3, etc. However since you're adding a limb with ID 1 then the only possibility is that limb 1 already exists on your object. Check your code to make sure you haven't already added a limb with the ID 1. If you haven't there's a possibility that your 3D modeling app has exported your object as several different limbs. Try adding the limb as 2, then 3, then 4, and so on and so forth, until you don't get the error.

Zaibatsu
18
Years of Service
User Offline
Joined: 1st May 2006
Location: Lost in Thought
Posted: 18th Jan 2009 01:25 Edited at: 18th Jan 2009 01:37
I know for a fact I haven't coded in a limb other than this one, so it must be milkshape. I'll try 2 or 3. Thank you.

EDIT: okay... it finally worked at limb 6... and then there was another problem.

The limb and the player model were switched. I made an actual turret model for the player, and the limb was made from a sphere, but this is what I get.



the turret revolves around the sphere... why?

I've included the turret model in the event that anybody thinks it's a problem with the model. If someone wants to take a look at the model to see why I needed to use limb 6, that would also be appreciated. Also, if you want it for your own project, that's ok.

Thank you for any help,
Brett Snow.

Attachments

Login to view attachments
Zaibatsu
18
Years of Service
User Offline
Joined: 1st May 2006
Location: Lost in Thought
Posted: 27th Jan 2009 05:40
No one has suggested anything in over a week, and I still haven't sorted out this problem. I'm reluctant to continue working on this project if the issue never gets sorted out. Any help anyone could offer would be appreciated.

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 27th Jan 2009 06:49
I discontinued that tutorial largely for the reason that there are better, faster, easier ways to do things than how I explained.

This is a prime example. You want to rotate a turret around, and shoot things with it. I assume right now you're putting a limb infront of it for an easy way to get the position to cast an intersection ray to.

If this is what you're aiming for, here's one way to do it:

First off you need to determine your control scheme. Ill do two different methods.

Method 1:

In method 1, lets assume you want to use the arrow keys to turn the turret left and right, and the spacekey to fire. Simple enough. Read through this demo, the comments explain whats happening:



So, pretty basic but you get the idea. If you wanted the player object to be able to move, you'll have to change the program a bit to check for intersection based on the player's position instead of 0,0,0. You will probably also want to introduce a timer system to delay shots, and another timer that displays a bullet flash between the player and the shot for a split second.


Method 2:

Method 2 is a bit more complicated. In this demo, you can move the player around with the ASWD keys, and aim with the mouse. The player is essentially a tank made up of two objects. The first object is the base of the tank, that always points in the direction the player is moving. The second object is the turret of the tank, that always points towards the mouse. Once again the target system from the first demo is carried over to this one.



So thats two ways of doing things in a top-down shooter. As you can see, you dont need to use limbs to get position data for ray checks, they end up being more of a hassle than a time saver like I originally thought when I wrote that tutorial.

Hope this helps,
- RUC

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 28th Jan 2009 04:37
No response at all? Did this help or not?

Zaibatsu
18
Years of Service
User Offline
Joined: 1st May 2006
Location: Lost in Thought
Posted: 28th Jan 2009 23:49
Sorry, I was gone for the day. I don't have much free time right now to look through this, but thank you for the help. I'll have some free time tomorrow and get back to you then.

Zaibatsu
18
Years of Service
User Offline
Joined: 1st May 2006
Location: Lost in Thought
Posted: 31st Jan 2009 06:23 Edited at: 31st Jan 2009 06:24
Well, after reading this several times and taking a few days to think about it; I've deduced that that is too complicated for me to understand. I'm not very good at this. My guess is that there's some kind of basic concept I either skipped over or didn't understand when I first started to learn programming.

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 31st Jan 2009 16:20 Edited at: 31st Jan 2009 16:27
What parts dont you understand? The best way to learn is to remove and alter things in the code and see what changes, along with looking up the commands you dont know in the index for better descriptions of what they do / how to use them. But if you outline which sections of the code you dont get, I can explain it or alter it to something simpler that might be a little more code but does the same task.

If you still want information on limbs, I made a post a long time ago explaining them:

link

Zaibatsu
18
Years of Service
User Offline
Joined: 1st May 2006
Location: Lost in Thought
Posted: 31st Jan 2009 21:29
Quote: "I can explain it or alter it to something simpler that might be a little more code but does the same task."


I'll try to specify what I don't understand. As for it taking more code if you alter it, more or less code isn't a problem for me, as long as it gets the job done.

What I have done recently though is modified the models. It looked funny for the base of the turret to rotate with the gun, so I split it into two separate models, turretbase.x and turretgun.x. The gun now swivels independently of the base, making it look better.

The source code has also changed now; not only because of the splitting of the turret model, but because I got rid of the code for the limb so I can implement a different method.

Here's the new source:


I've included a ZIP of the project file and the media.



One thing in your example code that I don't understand is the function. I was never any good with functions, and I don't understand any of the code inside the one you've got there. I also don't really understand raycasting. I kind of have the general idea of what it's supposed to do, but I have no idea how to use it.

Also, why exactly don't you use the
commands? And why do you use
to rotate the player model? That seems like it's more complicated than it needs to be.

Attachments

Login to view attachments
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 31st Jan 2009 23:02 Edited at: 31st Jan 2009 23:03
Quote: "What I have done recently though is modified the models. It looked funny for the base of the turret to rotate with the gun, so I split it into two separate models, turretbase.x and turretgun.x. The gun now swivels independently of the base, making it look better."


I dont know what you mean about the base of the turret rotating dependantly from the turret... in my example the base object is meant to be a placeholder for the tank, and the turret object is supposed to be a placeholder for the entire turret, allowing the entire turret to spin freely from the tank.
Quote: "
One thing in your example code that I don't understand is the function. I was never any good with functions, and I don't understand any of the code inside the one you've got there."


Functions are a fundamental part of programming. If you dont understand them, you need to do some research into tutorials on look for one of the many posts in these forums explaining them. Ill briefly go over them though...

You understand how commands work inside DBP I assume. Things like turn object right, or sync, or print. Every command is essentially a portion of code, that can be called at any time. Commands have an added benefit of taking parameters when called, these parameters can be anything, and used inside the function to do something.

The main benefit of functions is code simplicity and their ability to save time. Here's an example...

Say you wanted to position an object behind another object all the time, having it follow it around. How could you do this? Well the simplest way without using any difficult math or the newvalue commands, would be to position the follower object at the other object's position, rotate the follower object to the other object's angle, and then move it backwards a given distance. If you think this sollution through, it's easy to see that the follower object will always stay behind the other object. Here's a really basic example:



Right, before I go any further, if you dont understand how that code works, you need to go back to square one and read some beginner tutorials before moving on. Otherwise keep reading.

So thats a pretty basic way of making a sphere follow a cube. But now lets make it a little more complex, and say you wanted to make several objects follow behind the cube, at different distances. How would you do this? Well in simplest terms, you would copy the code used to orient the sphere behind the cube several more times for each object you want to position, and alter the distance / object data. Here's how that would look:



So thats a lot more code to do the same thing over and over again. This is where a function would come in handy. You could take this portion of code...



...and put it into a function, alter it to work for whatever object number and distance you specify in the function parameters when its called, and you've instantly reduced the amount of code you need to write and time you need to spend figuring out how things work / where a problem lies later on.

So to make a function in DBP, first you write the command FUNCTION, then the name you want for the function, then open and closed paranthesis, all on one line. Then you put the code you want the function to execute when called on the next lines, and finish with the ENDFUNCTION command. If you want to be able to pass the function values so the function can use those values, you create new variables inside the paranthesis and the function will reference them when called. One final note, is that functions can return values when called as well, just like OBJECT POSITION() returns a value for example. To return values from functions, you put the variable containing the return value at the end of the ENDFUNCTION line. Here's a simple example of a function that adds two numbers:



To call this function, you'd simply write:



So, going back to the original problem, if we wanted to put that object orientation code into a function, we could then give it two parameters, one for the object number we want to orient behind object 1, and one for the distance we want to move it back by. Here's how that final program would look:

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 31st Jan 2009 23:03
And finally...

[/quote]
And why do you use + Code Snippet

`Player Rotation
INC angle#, RIGHTKEY()-LEFTKEY()
ROTATE OBJECT player, 0, WRAPVALUE(angle#), 0


to rotate the player model? That seems like it's more complicated than it needs to be.
[/quote]

It might seem that way, but this is absolutely necessary. Here's why:

1. Using the turn, pitch, and roll object commands do not take into account eular rotations, and result in giving the object you're rotating incorrect angle data. If you want proof, here it is; I've taken the example I programmed you to explain functions, and replaced the object turning code with the turn object command. Watch what happens:



2. Another problem with DBP rotation is the single-axis rotation commands, something many people agree should not even be available in DBP, as they end up confusing the newcommers more than anything. When you rotate an object in DBP, DBP uses every axis to get the object to it's destination angle, rotating first on the x, then the y, then the z. Using the single-axis rotation commands like XROTATE or YROTATE or ZROTATE gives the false idea that the object will maintain it's other angle values, when this isn't the case. This is why I use ROTATE OBJECT filling in each angle I want, instead of the YROTATE OBJECT.

3. Finally, the wrapvalue command isn't necessary but should be called with the angle you're setting as well, to keep the angle value between 0 and 360. If you constantly increase an object's angle, it will internally store this angle constantly as well. It wont automatically wrap aroudn to 0 once it reaches to 360. So eventually you may end up with angles in the hundred thousands or higher. The wrapvalue command wraps the angle back around to a value under the 360 mark, and also ensures there are no negative angles.

Hope that helps.

Zaibatsu
18
Years of Service
User Offline
Joined: 1st May 2006
Location: Lost in Thought
Posted: 31st Jan 2009 23:20
Quote: "I dont know what you mean about the base of the turret rotating dependantly from the turret... in my example the base object is meant to be a placeholder for the tank, and the turret object is supposed to be a placeholder for the entire turret, allowing the entire turret to spin freely from the tank."


I meant in the turret model I made for the game.

Quote: "It might seem that way, but this is absolutely necessary"


I'll trust you on that.

I've successfully (sort of) have the turret rotating using the control system you say is necessary. The problem is, it rotates FAR too fast, so fast, it looks like a helicopter blade. I could control the value of rotation with my last method, I'm not sure how with this one.

Current Source Code:


RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 31st Jan 2009 23:29
You're not taking the time to understand your code. This is a simple one.

How are you calculating the speed to change the angle# variable? You're using LEFTKEY()-RIGHTKEY(). Why does this work? Leftkey() and rightkey() return a 1 if they're pressed and a 0 if not. So if the left key is pressed and the right isn't, then it will be 1 - 0, equalling 1. You're increasing the angle by 1. If the rightkey is pressed and the leftkey isn't, it will be 0 - 1, -1, thus the angle decreases by 1 (because increasing a value by a negative essentially decreases it). So to dampen this increasing value, you put brackets around the equation and multiply it by a decimal. For example INC angle#, ( RIGHTKEY() - LEFTKEY() ) *0.5 will slow the turn speed down by half.

Zaibatsu
18
Years of Service
User Offline
Joined: 1st May 2006
Location: Lost in Thought
Posted: 31st Jan 2009 23:57
Quote: "You're not taking the time to understand your code."

I tried to understand it.

Quote: "How are you calculating the speed to change the angle# variable? You're using LEFTKEY()-RIGHTKEY(). Why does this work? Leftkey() and rightkey() return a 1 if they're pressed and a 0 if not. So if the left key is pressed and the right isn't, then it will be 1 - 0, equalling 1. You're increasing the angle by 1. If the rightkey is pressed and the leftkey isn't, it will be 0 - 1, -1, thus the angle decreases by 1 (because increasing a value by a negative essentially decreases it). So to dampen this increasing value, you put brackets around the equation and multiply it by a decimal. For example INC angle#, ( RIGHTKEY() - LEFTKEY() ) *0.5 will slow the turn speed down by half."


Oh, it makes sense now. I've got it fixed. I'm gonna try to get the respawning function working.

Zaibatsu
18
Years of Service
User Offline
Joined: 1st May 2006
Location: Lost in Thought
Posted: 1st Feb 2009 23:32
I've spent the last 5 hours getting rid of all the placeholder models and textures. I got around to texturing my turret model,here's the final version:



and I replaced the hexagonal prism with a drill tank.:



RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 2nd Feb 2009 05:29
I dont see why you're working on modeling game assets when you dont even have a control scheme worked out yet.

Zaibatsu
18
Years of Service
User Offline
Joined: 1st May 2006
Location: Lost in Thought
Posted: 3rd Feb 2009 00:57
Quote: "I dont see why you're working on modeling game assets when you dont even have a control scheme worked out yet."


Because it's something I know how to do.

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 3rd Feb 2009 02:43
Well you're setting yourself up to fail working like that. Ive seen it a lot of times. Anyways goodluck.

Zaibatsu
18
Years of Service
User Offline
Joined: 1st May 2006
Location: Lost in Thought
Posted: 3rd Feb 2009 23:36
Quote: "Well you're setting yourself up to fail working like that."


It wouldn't be the first time.

Quote: "Anyways goodluck.
"


Maybe this one will turn out different.

Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 4th Feb 2009 01:47
well... i have nothing better to do, so i'll demonstrate to the best of my ability how to understand the code Ruccus posted above



"SYNC ON:SYNC RATE 0:AUTOCAM OFF:RANDOMIZE TIMER()"
I'm sure you know what the sync on and sync rate commands do, so i'll skip over those.

"autocam off"- when an object is made (when autocam is on, which it is by default), the camera moves back to the origin <0,0,0>, when autocam is off, then the camera stays in it's position.

"randomize timer()" - The randomize command is used in junction with the RND command. Basically, the randomize command sets the "Seed" value. All RND commands after the randomize command, will be determined by that seed value. For example, try entering this code:


if you execute that, you'll see that, given the same seed, the sequence of rnd numbers after that will be the same.


After that first line, theres some variables set up, pretty self explanitory.

POSITION CAMERA 0,300,0ITCH CAMERA DOWN 90

sets the camera position, and changes the pitch of the camera down. (pitch, yaw, roll, im not exactly sure which is which, but it rotates the camera)

Then, it makes, positions, and colors the objects.

Now for the function. You already said that you didn't understand this, so i'll explain them.

Take for example this code:


This is exactly the same as this code:


I'll leave it at that. If you still don't understand functions, theres plenty of rescources online if you just do a google search, but that might return alot of code in other languages. (doesn't really matter, the concept's the same)


Now for the main loop. I'll skip the "disable systemkeys command"
WHILE ESCAPEKEY() = 0
...
...
...
endwhile
end

This is basically what the do/loop is.
The while command is pretty simple.
if the command after the "while" command is true, after the "Endwhile" command is called, the loop will continue down from the while command to the endwhile command, then it repeats until the command after the "while" command is false.

In your regular DBPro loop, do/loop ends whenever you press the escape key.

This code:

well, it looks like you're already familiar with that.

This code is the hard part.


PICK SCREEN MOUSEX(), MOUSEY(), CAMERA POSITION Y()
mx# = CAMERA POSITION X() + GET PICK VECTOR X()
mz# = CAMERA POSITION Z() + GET PICK VECTOR Z()

pick screen screen x, screen y, distance

take this code:
pick screen mousex(), mousey(),10

imagine this: your camera/the viewer is given a random location, and random angle. Now, on your screen, imagine placing a finger on the place that your mouse is, and reaching into the screen by 10 units, in a straight line. That's what the pick screen command does. Since commands in dbpro can only return scalar values, you have to use the commands "get pick vector x", "get pick vector y", and "get pick vector z"


Hope that helped

Login to post a reply

Server time is: 2024-11-24 14:49:08
Your offset time is: 2024-11-24 14:49:08