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 / Theory: bullet code without bullets

Author
Message
TDP Enterprises
20
Years of Service
User Offline
Joined: 28th Mar 2005
Location: on or in front of my computer
Posted: 30th Mar 2005 03:19
I was wondering if anyone knew how to project a beam out of the front of a gun, tell if it's hitting anything, if it is what objects?, and then which is closer(i already have distance code) (example: if I press fire and the beam go's through a wall and an enemy is there, don't kill the enemy)I would greatly appreciate help on this subject because I believe it could speed up a game.

Oh, and I have heard of a Dll called ray casting or something and I prefer not to use Dlls so please, DBC source code only.
M Gaming
21
Years of Service
User Offline
Joined: 23rd Mar 2004
Location: Everywhere
Posted: 31st Mar 2005 07:33
Unfortunately DBC has no raycast command (intersect object) like DBPro. I don't know what might work, my only guess would be to use for-next loops and newxvalue, newzvalue.

M Gaming
Game: Parallel Dimension
Terabyte
22
Years of Service
User Offline
Joined: 28th Dec 2002
Location: UK
Posted: 31st Mar 2005 10:57
yeah i thought this idea when i saw the pick object command
unfortunatly thats in dbp
and you have to use .x objects for the level so it wont go through walls

but its dam accurate when youve got it running and very fast too

Dark Days Software
Sven B
20
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 1st Apr 2005 00:27
Maybe try object screen x()/y() command...
Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 19th Apr 2005 03:53 Edited at: 19th Apr 2005 03:54
I was thinking about this RIGHT NOW...what a coincidence, but i just thought, how about there was a long object (like a stretched out cylinder or something) coming out of the gun(but you cant see it), and if you shoot that make a variable called shooting, and make that variable =1, then perhaps you could so something like

if shooting>0
if object collision(streched object, enemy)>0
die=1
endif
endif

if die>0
position object enemy,999999999,9999999999,999999999
hide object enemy
inc score
endif

"Well, if he dies, it'll teach him not to do it again." - Me
dj blackdragon3710
20
Years of Service
User Offline
Joined: 5th Nov 2004
Location: In LaLa land
Posted: 19th Apr 2005 10:26
If you make the normal shooting code, put in Hide object oject number. That worked for me. And with that on, it didn't screw with the collision or anything.

It has been said that the body is a slave to the mind. Only the mind knows no freedom.
BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 20th Apr 2005 15:02
If you guys grab a hold of the NGC dll it has a full set of raycast commands.

Crazy Donut Productions
Current Project: A Redneck game
dj blackdragon3710
20
Years of Service
User Offline
Joined: 5th Nov 2004
Location: In LaLa land
Posted: 21st Apr 2005 01:37
I like doing everything the "Hard" way .

It has been said that the body is a slave to the mind. Only the mind knows no freedom.
Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 21st Apr 2005 01:43
cool. where do i get the ngc dll

"Well, if he dies, it'll teach him not to do it again." - Me
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Apr 2005 01:48
The only way you could do this mathmetically without having direct access to the vertices in the object, is to represent your objects with a simple, primitive shape. Maybe a cube or cylinder shape. And then search for a line-cube intersection algorithm. The line equation would basically be parameterized, which would allow you to determine what the closest object was by keeping track of which object returned the lowest value above 0 and under 1.

PETA - People for the Eating of Tasty Animals
Robot
20
Years of Service
User Offline
Joined: 27th May 2004
Location:
Posted: 21st Apr 2005 02:56
Sparky's collision dll might help you here
http://forum.thegamecreators.com/?m=forum_view&t=31051&b=5

The happenings of tommorow are behind us now
Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 21st Apr 2005 07:24
i found out that if you shoot your bullet at the same speed as the distance of the enemy then you cant see it and the shot is instantanious, the only problem is if you have lots of enemies you need to know which one your facing

"Well, if he dies, it'll teach him not to do it again." - Me
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 21st Apr 2005 13:14
To all,

I have attached to this post a demo, in 2D(no media), of a method of raycasting I have created for you. The bullet is simply a laser beam. Therefore, how to implement a bullet object with smoke or any other effects, which can be seen, to match up to the cast ray correctly, will take some more experimentation on your part. Though, as I have time, I will run tests and return the results.

+NanoBrain+
Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 22nd Apr 2005 01:48
do you think you could make that in 3d?

"Well, if he dies, it'll teach him not to do it again." - Me
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 22nd Apr 2005 02:26
I use Sparky's .dll with DBPro, but with DBC Enhanced you can use the same plugin - that returns the object number, collision point, bounce angle, normal of the polygon it hits, and distance to the collision point - everything you need really. I use it for bullet collision, decals (which change depending on the object), and line of sight AI checks. It is a little more complex to use it for player collision though, luckily I'm sure there's code somewhere around the snippets forum that shows an example of FPS style sliding collision.

I think you can still buy DarkMatter1 and get the enhancement pack for DBC that makes it possible to use sparky's .dll. Saying that though, perhaps upgrading to DBPro makes more sense in the long run.


Van-B

Quote: "How could I condescend you?, you don't even know what it means!"

Van-B's mom.
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 22nd Apr 2005 14:05
Van B,

Yes, the dll is excellent! But, I always like to suggest the wisdom of experimentation to create the same effects. Which, in DarkBasic, is possible to do with the upgrade to version 1.13.

Zotoaster,

Do you understand the code I gave here?

+NanoBrain+
Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 23rd Apr 2005 02:39
uhhh, probably, what i mean is: can it be re-writen in 3d

"Well, if he dies, it'll teach him not to do it again." - Me
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 26th Apr 2005 13:46 Edited at: 26th Apr 2005 13:48
Zotoaster,

Sorry for such a delayed response to your last post. I have been coding a demo of coded raytracing collision in 3D. There were many bugs within it which I had to fix. However, I am now finnished and the source code is attached to this post. In the demo, the user is able to shoot in all three dimensions. Unlike the 2D demo I wrote, the bullet can be seen.

As the bullet coasts along, 'raytracing' is checking unit by unit ahead of it for any collision, up until it's next stopping point. Since the raytracing only checks in segments of a full unit, the accuracy is not that high. I have only made it to check every unit for the reason that real numbers would not allow the raytrace FOR NEXT loop to function at all. However, if the loop is switched to a REPEAT UNTIL or some other type of loop, and the code is edited a bit, accuracy can come to the decimal point.

Also, I did not create a collision box around the bullet for more precise collision. Simply, the collision engine checks the bullet's absolute coordinate position. However, I only created this program to demo raytracing, not collision.

In conclusion, the source code is well commented to help you understand its works.


+NanoBrain+
TDP Enterprises
20
Years of Service
User Offline
Joined: 28th Mar 2005
Location: on or in front of my computer
Posted: 28th Apr 2005 08:05
I was actually wondering if it was possible to to create a sphere within a cube with one side missing, then check if that sphere can see a enemy and if if so, is the fire button being pressed, if so then take 10 off of the enemies health. is there a way to do this?
aks74u
20
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: arizona
Posted: 28th Apr 2005 08:27
hey nano brain , how would you make the bullets unacurrate like a real gun?thx

Over And Out.
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 28th Apr 2005 11:36
Delta Commander,

I suppose that you could make a box which follows along with the player, rotating with him, pointing fowards, or whatever direction wished. Make two functions, one which checks collision between the environment and the box, and one which checks collision between the animate enemies and the box.

In a program loop grab the values of these functions in seperate variables. Then, check if they are both 'on'(boolean), as to say that the box has collided with both an enemy and the environment. If so, then check which is closer, as you stated in the beginning of this post. The distance formula for all three axises to check distance between the character and the object/enemy, written in DarkBasic is sqrt((player_x - object__x)^2 + (player_y - object_y)^2 + player_z - object_z)^2).

Though, this method would be easier to code, I would not suggest it due to high inaccuracy and uneeded polygons.

aks74u,

To make the bullet paths inaccurate, would take a simple method of off-setting it's starting angles by a bit, randomly. Let's look at the piece of code from my program below. I will show you how to impelement a single integer value off-set to both angles. The example is heavily commented for your instruction.




+NanoBrain+
drummer boy
20
Years of Service
User Offline
Joined: 2nd May 2005
Location:
Posted: 2nd May 2005 11:56
boo ...... ha i scared you!!!

Login to post a reply

Server time is: 2025-05-23 13:02:01
Your offset time is: 2025-05-23 13:02:01