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 / Shooting- Need More Help

Author
Message
John Avon
19
Years of Service
User Offline
Joined: 12th Apr 2005
Location: Avon Indiana USA
Posted: 28th Apr 2005 08:19
I have tried to shoot bullets from a gun turret and keep the turret visable while the bullets fly. it take me over 100 lines of code to shoot in 3 direction. Thats a sub per direction. 45 degrees a part another 2 SUBs for the target and coincidence matching. This Ain't Good!
Could Someone Please send a code snippet that is self comtained that allows "Bullets" to fly straight while a Gun turret is Moving.
I'm omly half way throught the "Beginners Guide To DB Programing", But can say it one of the poorest Tech Manuals I have ever Read. Somebuddy help Please. JG

JohnGillespie
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 28th Apr 2005 15:26 Edited at: 28th Apr 2005 17:13
Here's a very simple bullet code. It uses only 1 global variable for timing. The rest is tracked by the bullet objects themselves.

I didn't comment the code - because it's so small and easy to understand. If you have any questions about it, just post to this thread and I'll check back.

By the way, it's 3D, but you can easily apply the same concepts to 2D. It's a bit more work though.

Hope this helps


"Droids don't rip your arms off when they lose." -H. Solo
REALITY II
NanoBrain
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 28th Apr 2005 16:14 Edited at: 28th Apr 2005 16:17
John Avon,

If you have coded the bullets to take the same angle or position of the turret while they are 'flying', that's excatly what they will do. The trick to seperate the bullet from the gun, to that the bullet continues to go the angle it started with initially, is to give the bullet values from seperate variables.

Let's say that the turret is facing an angle of 315o(slanted up) on the x axis. When you press the fire button, whatever you have coded it to be, mouselick or any keyboard key, first assign the turret's angle value to a variable which can be used by the bullet, seperate from the turret's angle variable. Then, use this variable as the bullet's constant for an angle. Try this code snippet below.



In this code I did not make everything to function the way I usually do, with sin and cos and other maths. Simply, I used DarkBasic commands, but have placed REM statements in where I believe will help you to understand what's going on. Also, the turret's motion is quite awkward. However, I did not create this program to perfect it, but to show how to seperate a bullet's movement from the turret's movement.


+NanoBrain+
John Avon
19
Years of Service
User Offline
Joined: 12th Apr 2005
Location: Avon Indiana USA
Posted: 28th Apr 2005 22:29
Thank You both very much. Code looks good. I`d also stopped about 1 chapter to soon and got just plain fustrated.Think I'll be a day or two before getting back. I did get locked - up this week.Thanks once more. JG

JohnGillespie

Login to post a reply

Server time is: 2024-09-23 19:28:58
Your offset time is: 2024-09-23 19:28:58