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 / How do I make a bullet hit a moving target and then come back to me?

Author
Message
Programador hispano
18
Years of Service
User Offline
Joined: 11th Jul 2006
Location: Dallas, TX
Posted: 27th Jul 2006 19:55
I am using DarkBasic Classic.
I made this code and I have been playing with it for a while and I can not make it do what I want.
My player is controlled with the cursor keys
my target is controlled with the mouse
left mouse click to shoot.

I want to shoot at the target, hit it every time, and then make the bullet come back to me, no matter where I am in the matrix.
Is that posible?

Can somebody help me please?

This is my code so far, I am sorry, is messy. You don't need any extra media...


` Program creted by Eduardo Herrera
` July 2006

`set up
sync rate 40
sync on
autocam off
hide mouse

` make matrix
` this matrix is only for reference point
make matrix 1,30,30,30,30

`make target and color it
make object box 1,2,0.1,2 :
xrotate object 1,90
color object 1,rgb(10,10,10)

`make player
make object cylinder 2,1
color object 2,rgb(200,0,0)
` xrotate object 2,90

`make bullet
make object sphere 3,0.5
color object 3,rgb(0,250,0)
hide object 3

`initialize player position
playerxpos#=15
playerzpos#=15
`main program
do

`get position of mouse
posmousex#=mousex()
posmousez#=mousez()

`print on screen position of target
set cursor 0,0 : print "Get mouse to position 30 on x coordinates to start"
set cursor 0,15 : print "Position of mouse on x coordinates: ",posmousex#
set cursor 0,30 : print "Use mouse to move target left or right..."
set cursor 0,45 : print "Use cursor keys to move player left, right,up or down"
set cursor 0,60 : print "left mouse click to shoot"

` mouse bounderies on x on the back side
if posmousex#<31 then posmousex#=31
if posmousex#>60 then posmousex#=60

` player stays in bounderies on x position
if playerxpos#=<0 then playerxpos#=0
if playerxpos#=>30 then playerxpos#=30

`player stays in bounderies on z position
if playerzpos#=<0 then playerzpos#=0
if playerzpos#=>30 then playerzpos#=30

` player movement
if rightkey()=1 and playerxpos#>=0 and playerxpos#=<30 then playerxpos#=playerxpos#+0.3
if leftkey()=1 and playerxpos#=>0 and playerxpos#=<30 then playerxpos#=playerxpos#-0.3
if upkey()=1 and playerzpos#>=0 and playerzpos#<=30 then playerzpos#=playerzpos#+0.3
if downkey()=1 and playerzpos#>=0 and playerzpos#<=30 then playerzpos#=playerzpos#-0.3


` bullet creation
if mouseclick()=1 and bulletlife=0
` position bullet in the gun
position object 3,playerxpos#,1,playerzpos#
set object to object orientation 3,2
bulletlife=60
show object 3
endif
`bullet path
if bulletlife>0
dec bulletlife
move object 3,0.5
if bulletlife=0 then hide object 3
endif

` collision detection
col_with_target=object collision(3,1)

if col_with_target=1
bulletlife=0
hide object 3
endif

` positioning player
position object 2,playerxpos#,1,playerzpos#

` positioning target
position object 1,posmousex#-30,1,30

` positioning camera
position camera 15,20,-10
point camera 15,10,0

sync

loop
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 28th Jul 2006 01:28
Try POINT OBJECT and some flag values, like this. I had to change your code a lot, for it was not doing what you say you want it to. Bulletlife is now 1 until it comes back to the player.



Type [ code ] and [ /code ] without the spaces to create a code snippet box like mine

Programador hispano
18
Years of Service
User Offline
Joined: 11th Jul 2006
Location: Dallas, TX
Posted: 28th Jul 2006 08:02
This is an incredible programming that you do. Thank you very very much. I am sorry I was not especific about my code at the beginning of the post, I tried to do it by myself, then I just fixed it so it would shoot, so nobody would be confused with the mess that I made before. Believe me, it was bad. I had my bullet shooting down at one time. Thank you. I will mention you in my game.

Would it be posible now to modify the code ( of course I am gonna try hard to do it by myself, I don't want to sound like you are doing all the work ) so when you shoot at the target, being able to move the target without the bullet following the target, just have the bullet bounce on a wall and come back to you? I don't know if I explained my self, just shoot then move the target around and not having the bullet follow the target just bounce a wall and then come back to the player. Well, thank a lot, I am gonna go try to change the code again. Eduardo.
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 28th Jul 2006 13:17 Edited at: 28th Jul 2006 13:33
Thanks There's probably a better way to do it, but I wanted to stick to what you were doing instead of checking for a better way and making your code unreadable to you.

Anyway, I have modified the code. Try to figure it out first though. If you can't get it you can try this:




[Edit]
And while I'm at it, here's a version with better mouse movement for the Target. I found it a bit jumpy before. It uses MOUSEMOVEX(), which returns the strength of the player's mouse movement on the X axis. After it, you will see a "/10". That divides the strength for slower movement. Increase this number to make the movement slower, and decrease it to make it faster.




[/Edit]

Programador hispano
18
Years of Service
User Offline
Joined: 11th Jul 2006
Location: Dallas, TX
Posted: 28th Jul 2006 20:41
Thank you, but I think I didn't explain myself properly, What I wanted is to target then shoot then re-target somewhere else without the bullet following the target, the bullet just has to hit where the target was before then come back to the player. I am sorry. You are really good, this is my first program, I am understanding your code, thanks you alot. I am trying here, but by the time I come from work and understand the code, you already have a better one, don't get me wrong I appreciate your help. I am an ok 3d modeler, if you need help don't hesitate to ask. thank you for your time and patience.
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 29th Jul 2006 16:39 Edited at: 29th Jul 2006 16:39
Does the code above not do that? I still do not understand...

Programador hispano
18
Years of Service
User Offline
Joined: 11th Jul 2006
Location: Dallas, TX
Posted: 30th Jul 2006 07:31
hello I attached a picture of the game that I am trying to make, it is called discs of tron.

# 1 is the target that we are trying to work with
# 2 is the opponent
# 3 is the player and
# 4 is a disk that is flying from the opponent.

The target is going around the 4 walls.

I am gonna have 3 bullets(discs), and shoot 1 by 1, when you want to shoot you aim( put the target behind him ) at the opponent on the other platform and shoot, then if he moves the disc will hit the wall and come back to you, and while the first disc is going you have to be able to re-target the opponent (put the target behind him again ) and shoot the second bullet without the first bullet following the target and so on, when the opponent disc and yours touch each other they explode and you get another disc and the opponent gets another as well, so there is always 3 discs for player and opponent. There is a point in the game where there is up to 6 discs flying around plus bombs. But I only need help with the targeting system for now, I really really want to try to program the rest. Thanks for your time. Tell me if you don't understand. I am sorry for not being able to explain it better.

Attachments

Login to view attachments
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 2nd Aug 2006 21:36
ok I think i understand

basically you will want to be moving your disk with x,y values. For instance you would have a xspeed# variable and a yspeed#(or zspeed# if you need it) variable then just position the disk at whatever it's position is +xspeed# and yspeed#. This prevents it from following the target.

As far as hitting the opponents disc is concerned, just check for collision between the 2 discs and if they are colliding, delete them and put an explosion animation there. you would do this like this

Login to post a reply

Server time is: 2025-05-25 06:38:09
Your offset time is: 2025-05-25 06:38:09