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.

Code Snippets / Bullet Code Snippet with intersect object command (free to use)

Author
Message
Scorpyo
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 13th Dec 2003 17:01
got a good performance with this..
controls are printed on screen
with some tweaking could be used to calculate sliding collisions for x landscapes and lighting normals
free to use
cheers all
Scorpyo


Mussi
21
Years of Service
User Offline
Joined: 27th Jan 2003
Location: Netherlands
Posted: 14th Dec 2003 15:36
this is very cool , but I cant understand you code :/, can you tell me what you did to get the correct angles? don't have to go in detail(so no codes or stuff), just how you did it

Specs: AMD Athlon 1800, 256 DDRRam 266mhz, 80GB HD 7200rmp U133, Geforce 4 Ti4400 128mb ddr sdram

http://www.apollostudio.nl/
Scorpyo
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 14th Dec 2003 20:53
1) check_hitspot

first you draw an intersect ray from gun to target using the gun orientation angles (gay#,gax#) in order to check the distance of the hit point (hit#)
then you find the real world coords of that point using hit#

newbx#=newxvalue(gx#,gay#,hit#)
newbz#=newzvalue(gz#,gay#,hit#)
newby#=newyvalue(gy#,gax#,hit#)

position bullet plane there
but since this point is found with an intersect ray not parallel to the z or x axis you need some adjustment (parallax error)

2) position_bullet
use 2 rays parallel to z axis from above position and find the distance of the bullet from the real target surface giving you the correction:
hit2#=intersect object(2,newbx#,newby#,newbz#-100,newbx#,newby#,newbz#+100)
hit3#=intersect object(shootcount,newbx#,newby#,newbz#-100,newbx#,newby#,newbz#+100)
adjustz#=100-(hit2#-hit3#)
2 is the target , shootcount is the bullet number

adjust bullet position:
position object shootcount,newbx#,newby#,newbz#-adjustz#

bullet_ytilt
at this point it's easy..
you have your bullet plane with its center at the hit point exactly on the wall surface,perfectly vertical and zero y rotated (VERY IMPORTANT)
now simply find the y tilt angle casting a ray some x units (10 in this case) away from the center of the bullet (x axis parallel) so you can get the lateral distance (deltay#) of the bullet plane from the wall

get the y tilt angle from that value:
bay#=atan(deltay#/10)

and y rotate accordingly:
yrotate object shootcount,bay#

now the bullet is y rotated to the wall but not x rotated


bullet_xtilt
same trick as above BUT:
to get the x rotation we need to cast a check ray exactly ortogonal to the bullet plane so we will find the new from/to values near the bullet position for the intersect ray:
newfrombix#=newxvalue(newbx#,bay#,-100)
newfrombiz#=newzvalue(newbz#,bay#,-100)
newtobix#=newxvalue(newbx#,bay#,200)
newtobiz#=newzvalue(newbz#,bay#,200)

now we check 10 units away from center along the y axis in that direction (same trick as for y tilt):
xdistbullet#=intersect object(2,newfrombix#,newby#+10,newfrombiz#,newtobix#,newby#+10,newtobiz#)
xdisttarget#=intersect object(shootcount,newfrombix#,newby#+10,newfrombiz#,newtobix#,newby#+10,newtobiz#)

find the deltax in order to calculate the x tilt angle and rotate

deltax#=xdistbullet#-xdisttarget#
rem translate found value to x tilt angle for bullet plane
bax#=atan(deltax#/10)
xrotate object shootcount,bax#

that's basically it..

cheers
Scorpyo
Mussi
21
Years of Service
User Offline
Joined: 27th Jan 2003
Location: Netherlands
Posted: 14th Dec 2003 21:25
Thanks a billion, I had something similar to that but the angles just wouldn't come out correct cuz I was calculating the angles before moving the plane

Specs: AMD Athlon 1800, 256 DDRRam 266mhz, 80GB HD 7200rmp U133, Geforce 4 Ti4400 128mb ddr sdram

http://www.apollostudio.nl/
comando 300
20
Years of Service
User Offline
Joined: 23rd Nov 2003
Location:
Posted: 7th Jan 2004 04:52
it's for DBC or DBP?
cuz it's giving an error

Is just of those days when you don't wanna wake up everything is *****, everybody sucks you really don't know why, but you wanna justify rippin' someone head off!
Rpg Cyco
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Australia
Posted: 7th Jan 2004 06:43
Its for DB Pro only, DBC doesn't have the intersect object command.

l8ter

Rpg Cyco

Login to post a reply

Server time is: 2024-05-04 05:55:48
Your offset time is: 2024-05-04 05:55:48