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 Professional Discussion / How to use raycast for Bullet Collision

Author
Message
gopherbro 94
17
Years of Service
User Offline
Joined: 21st Dec 2008
Location:
Posted: 21st Jun 2010 23:50
I made bullets for my game and they fly straight and in the right direction, the only problem is that I cant figure out how to use Sparkys raycasting for bullet collisions.

Here is my bullet code:

Sixty Squares
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 22nd Jun 2010 00:05
I'm not sure what your bullets are colliding against based on the code you've posted, but assuming your testing for collision against one or more world objects, here's the lowdown.

The way raycasting works is that it shoots an invisible laserbeam from one point to another. If the laserbeam hits something along the way, then the raycasting command will tell you. However, you have to say what that "something" is. SC_RAYCAST will check for collision against a certain object, while SC_RAYCASTGROUP will check for collision against a group of objects. These groups are defined when you use SC_SetupObject to setup your objects for collision.

As for the bullets, the answer is simple. Each loop, you'll want to recorod the position of your bullet before it moves. Then, you'll want to move the bullet forwards like you normally do. Then, you'll want to record its position again in a different set of variables. The thing to do now is to "shoot a laserbeam" from where the bullet was before it moved to where it is now. If the laserbeam hits one of your world objects, then the bullet just tried to go through a wall. If it didn't, then let the bullet keep going . The raycasting commands will always return a 0 if the laserbeam doesn't hit anything. If it hits something, then some other number will be returned depending on the command you used.

gopherbro 94
17
Years of Service
User Offline
Joined: 21st Dec 2008
Location:
Posted: 22nd Jun 2010 04:23
ok I got the collision to work, thanks. But the problem is that since the arrow is constantly moving, but hidden, it collides without ever having been fired!! I think what happens is the bullet starts positioned at the camera, but the loop causes it to keep moving forward, then when the mouse is clicked, it moves back to the camera, and then continues to move. so when the bullet is just flying, before it gets fired, it collides and messes up the whole system. Is there anything I can do about this?
Mychal B
16
Years of Service
User Offline
Joined: 21st Jul 2010
Location: Coos bay, rainville
Posted: 5th Sep 2010 02:24
give the arrow a set amount of life hide it and put it in a trivial out of the way location whe the life is 0.
Also make sure that you put something like "if bulletlife > 0 then move object mybullet,5" to keep the bullet from moving when you put it out of the way

Login to post a reply

Server time is: 2026-07-22 16:14:59
Your offset time is: 2026-07-22 16:14:59