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.

3 Dimensional Chat / gun attached to view

Author
Message
SGT KOOLAID
21
Years of Service
User Offline
Joined: 6th May 2004
Location: NYC
Posted: 3rd Jul 2004 17:30
how do i attach my M4 to my view and have it follow me whereever i go?

here is the code i have so far some used to help me learn the process of coding properly.
i appreciate any and all help, thanx to Kensupen and Lokidecat who wrote the code i used forming basic collsion for my level

rem my new level here goes nothing.
autocam off
set image colorkey 0,0,0

color backdrop 0
set camera range 1,10000
set camera FOV 65
set ambient light 100
set display mode 1024,768,32
fog on
fog color 222,184,135
fog distance 2000


make object sphere 2,10

rem grid level 01
load object "testlevel.x",1

set object cull 1,2
set object filter 1,2
dir$=get dir$()

`***************************
`.X Model sliding collision
`By Kensupen and Lokidecat
`Nerdsoft Creations (C) 2003
`***************************

`Height cam is off the ground
charht#=5
`speed to move
spd#=3
`set the radius for collisions
radius#=10.0
`set initial camera position
position camera 0,charht#,0
yrotate camera 90

`number of checks
`the lower this number is, the more off the collisions will be vs. any rotated object.
`also, the lower the number, the more speed it runs at.
`lowest for rotated collision is 4(non rotated/box collision) max is 360, but 360 is WAAAY slow
`I'd advide is you play with this number to keep with a multiple of 4
checks=8
if checks<4 then checks=4
if checks>360 then checks=360
`width of the angles
angwidth=360/checks
`make arrays for collision data
dim ang#(checks-1,2)
dim sort#(checks-1,2)


do
set cursor 0,0
print "Sync Rate set at ",srate," Press Enter to change"
print "FPS:",screen fps()
print "polygon count:", statistic(1)
hide mouse

if scancode()=0 then hold=0
if returnkey()=1 and hold=0
hold=1
if srate=60
srate=0
else
srate=60
endif
sync rate srate
endif


rem control player movement
cx#=camera angle x(0) : cy#=camera angle y(0)
if upkey()=1 then xrotate camera 0,0 : move camera 0,3.2 : xrotate camera 0,cx#
if downkey()=1 then yrotate camera 0,0 : move camera 0,-3.2 : xrotate camera 0,cx#
if leftkey()=1 then yrotate camera 0,cy#-90 : move camera 3.2 : yrotate camera 0,cy#
if rightkey()=1 then yrotate camera 0,cy#+90 : move camera 3.2 : yrotate camera 0,cy#
if wrapvalue(camera angle x(0))>40 and wrapvalue(camera angle x(0))<180 then xrotate camera 0,40
if wrapvalue(camera angle x(0))>180 and wrapvalue(camera angle x(0))<280 then xrotate camera 0,280


mcx#=wrapvalue(mcx#+mousemovey()*.5)
mcy#=wrapvalue(mcy#+mousemovex()*.5)
rotate camera mcx#,mcy#,0

`The main sliding collision code
gosub _collision
`My code to walk up a ramp if the angle isn't too steep
gosub _ramp
`A just in case reset
if spacekey()=1 then position camera 0,200,0

sync
loop

_ramp:
`get positions again
cx#=camera position x()
cz#=camera position z()
`Get your old height
oldht#=camera position y()
`calc new height using intersect object from the old height down charht# units
sub#=intersect object(1,cx#,oldht#,cz#,cx#,oldht#-(charht#*2),cz#)
ht#=(oldht#+charht#)-sub#
if sub#=0 then ht#=charht#

rem apply simple gravity to player
position camera camera position x(),camera position y()-0.1,camera position z()
position camera cx#,ht#,cz#
return

_collision:
`make 72 collision points. You can use more or less, but this number seems to work good.
`These are vectors every 5 degrees from the camera position out.
`They return the distance when they hit an object
for x=0 to checks-1
chx#=newxvalue(cx#,x*angwidth,100)
chz#=newzvalue(cz#,x*angwidth,100)
ang#(x,1)=intersect object(1,cx#,cy#,cz#,chx#,cy#,chz#)
if ang#(x,1)=0 then ang#(x,1)=999999
ang#(x,2)=x*angwidth
sort#(x,1)=ang#(x,1)
sort#(x,2)=ang#(x,2)
next x

`sort the array to find the closest object and it's degrees
for x=0 to checks-2
for y=x+1 to checks-1
if ang#(x,1)>ang#(y,1)
temp#=ang#(x,1)
temp2#=ang#(x,2)
ang#(x,1)=ang#(y,1)
ang#(x,2)=ang#(y,2)
ang#(y,1)=temp#
ang#(y,2)=temp2#
endif
next x
next y
`This is the closest wall and what degrees you would face to see it
print "Angle to closest wall:",ang#(0,2)
print "Distance to that wall:",ang#(0,1)
`find +-90 degrees from the closest one for when you walk into a corner so it doesn't shake
prev=wrapvalue(ang#(0,2)-90)/angwidth
nxt=wrapvalue(ang#(0,2)+90)/angwidth
newd#=radius#-ang#(0,1)
newa#=wrapvalue(ang#(0,2)-180)
newd1#=radius#-sort#(prev,1)
newa1#=wrapvalue(sort#(prev,2)-180)
newd2#=radius#-sort#(nxt,1)
newa2#=wrapvalue(sort#(nxt,2)-180)
`if you are less than radius from a wall, push you out to 20 from it
if ang#(0,1)<radius# and ang#(0,1)>0.0
repx#=newxvalue(cx#,newa#,newd#)
repz#=newzvalue(cz#,newa#,newd#)
position camera repx#,cy#,repz#
endif
cx#=camera position x()
cz#=camera position z()
`this is if you are coming into a corner, this pushes you sideways
if sort#(prev,1)<radius# and sort#(prev,1)>0.0
repx1#=newxvalue(cx#,newa1#,newd1#)
repz1#=newzvalue(cz#,newa1#,newd1#)
position camera repx1#,cy#,repz1#
endif
cx#=camera position x()
cz#=camera position z()
`and the other way. above is left, this is right
if sort#(nxt,1)<radius# and sort#(nxt,1)>0.0
repx2#=newxvalue(cx#,newa2#,newd2#)
repz2#=newzvalue(cz#,newa2#,newd2#)
position camera repx2#,cy#,repz2#
endif
return
Peter H
21
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 3rd Jul 2004 22:58
have you tried the "lock object on" command?


Formerly known as "DarkWing Duck"
SGT KOOLAID
21
Years of Service
User Offline
Joined: 6th May 2004
Location: NYC
Posted: 4th Jul 2004 08:51 Edited at: 4th Jul 2004 08:51
no not really i havent. not sure how to make it as i dont know where to start

this is what i started with

Make main player object and hide it
MAKE OBJECT CUBE 1,10
HIDE OBJECT 1
`Attach a limb and delete the mesh
MAKE MESH FROM OBJECT 1,1
ADD LIMB 1,1,1
DELETE MESH 1

`Make a weapon and attach it to the limb
load object "m4.x", 2
GLUE OBJECT TO LIMB 2,1,1

i got the box to attach to the gun but i cant for some reason attach the gun or whatever is responsbile to my view. what am i doing wrong
SGT KOOLAID
21
Years of Service
User Offline
Joined: 6th May 2004
Location: NYC
Posted: 4th Jul 2004 10:59
also did it like this still doesnt show up when i attach it


_load_gun:

GunObj=10 : load object "m4.x",GunObj
return

rem Setup gun for player
lock object on GunObj
scale object GunObj,2,2,4
rotate object GunObj,90,0,0
position object GunObj,10,-1,1
disable object zdepth GunObj

still stumped. the guns disappears now. any one how i can attach it? could really use some help please
AlecM
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Concord, MA
Posted: 4th Jul 2004 12:23
This DBP? if so read the tutorial that comes in the manual.


Buy it
Balid
21
Years of Service
User Offline
Joined: 21st Nov 2003
Location: MI, USA
Posted: 4th Jul 2004 14:54
SGT KOOLAID,

This may the reason you do not see your M4:

position object GunObj,10,-1,1

start off with its XY location to zero and its Z to 2 (position object GunObj,0,0,2), if your M4 is to small you will not see it if its within 1 unit from the camera. Then move it a little bit, like one unit at a time until you get it where you want. Because right now its TOOOOOO far to the right for you to see it.

May be 'fix object rotation' after rotating it 90 degrees. It may or not matter now but it may in the future.

SGT KOOLAID
21
Years of Service
User Offline
Joined: 6th May 2004
Location: NYC
Posted: 4th Jul 2004 17:22 Edited at: 4th Jul 2004 17:23
yea i figured it out it attaches now. ended up being simple.

here is the code i did

rem attach a gun to self
load object "m4.x", 2
lock object on 2
position object 2, -5,-5,-10
rotate object 2, 90,-90,-90

check the website out added it.
its amazing how dbpro can so simplistic its scary. well anyway i appreciate the help. back to work again.

Login to post a reply

Server time is: 2025-06-30 03:09:08
Your offset time is: 2025-06-30 03:09:08