I am trying to make a Mini Golf Game with the Newton Wrapper. I looked at the tutorials and even searched the forum for help. I got some help and solved most of my problems but i really need help on this question and i cant find it when i search the forum.
my question is when i put velocity on the golf ball and i hit it. It moves and hits a wall and bounces off like it should. Well it keeps on moving after it it the wall I add the friction but the ball keeps on moving. here is the code for that
sync on
sync rate 30
hide mouse
ndb_newtoncreate
`-------
`gravity
`-------
NDB_SetVector 0.0,-100, 0.0
NDB_SetStandardGravity
world = NDB_NewtonMaterialGetDefaultGroupID()
ball=NDB_NewtonMaterialCreateGroupID()
NDB_NewtonMaterialSetDefaultFriction world,ball,1, 1
Anyway it doen't work if slows done but the ball still keeps on moving. it never completely stops moving
Can anyone help me with this problem. Thanks in advance and here is the rest of the coding from my game so far so you guys can look through it and see whats wrong. if there is nothing wrong tell me what i can add to it to get what i am looking for.
sync on
sync rate 30
hide mouse
ndb_newtoncreate
`-------
`gravity
`-------
NDB_SetVector 0.0,-100, 0.0
NDB_SetStandardGravity
world = NDB_NewtonMaterialGetDefaultGroupID()
ball=NDB_NewtonMaterialCreateGroupID()
NDB_NewtonMaterialSetDefaultFriction world,ball,1, 1
testlevel()
`----------
golf ball
`----------
`45.93
make object sphere 1,5
col=ndb_newtoncreatesphere(5,5,5)
sphere= ndb_newtoncreatebody(col)
ndb_buildmatrix 0,0,0,0,0,0
ndb_newtonbodysetmatrix sphere
ndb_calculatemispheresolid 10,5
ndb_newtonbodysetmassmatrix sphere,10
ndb_newtonreleasecollision col
ndb_bodysetdbprodata sphere,1
ndb_bodysetgravity sphere,1
NDB_NewtonBodySetMaterialGroupID sphere,ball
NDB_NewtonMaterialSetCollisionCallback world,ball
`--------------
`load golf club
`--------------
load object "golf club.x",2
scale object 2,400,400,400
position object 2,0,-20,0
time# = NDB_GetElapsedTimeInSec()
time# = NDB_GetElapsedTimeInSec()
make camera 1
do
time# = NDB_GetElapsedTimeInSec()
NDB_NewtonUpdate time#
`move golf club
if leftkey()=1
yrotate object 2, wrapvalue(object angle y(2)+10)
endif
if rightkey()=1
yrotate object 2, wrapvalue(object angle y(2)-10)
endif
`-----------------
`move ball
`----------------
if spacekey()=1 and count=0
time=100
play object 2
x1# = camera position x(1) : y1# = camera position y(1) : z1# = camera position z(1)
move camera 1,1.0
x2# = camera position x(1) : y2# = camera position y(1) : z2# = camera position z(1)
move camera 1,-1.0
unit_x# = x2# - x1#
unit_y# = y2# - y1#
unit_z# = z2# - z1#
vel_x# = unit_x# * 300
vel_y# = unit_y#
vel_z# = unit_z# * 300
NDB_SetVector vel_x#, vel_y#, vel_z#
NDB_NewtonBodySetVelocity sphere
count=100
endif
`-----------------
`camera
`------------------
ay#= object angle y(2)
X# = Object position x(2)
Z# = Object position z(2)
Rem get new camera position and store in cZ# and cX#
cZ# = Newzvalue(Z#,aY#-180,100)
cX# = Newxvalue(X#,aY#-180,100)
Rem position camera
Position Camera 1, cX#,20,cZ#
Rem point the camera at the player object
Point camera 1, X#,object position y(2),Z#
if controlkey()
obj = NDB_DebugMakeNewtonObject()
set object light obj, 0
else
obj = 0
endif
sync
loop
ndb_newtondestroy
end
if memblock exist(1) then delete memblock (1)
function testlevel()
`-----------------
`level
`-----------------
load object "test level.x", 3
col = NDB_NewtonCreatetreecollision( 3 )
Floor = NDB_NewtonCreateBody( col )
NDB_BuildMatrix 0.0, 0.0, 0.0, 0.0, -20.0, 0.0
NDB_NewtonBodySetMAtrix Floor
NDB_NewtonBodySetDestructorCallback Floor
NDB_BodySetDBProData Floor, 3
NDB_NewtonBodySetMaterialGroupID Floor,world
position object 3,0,-20,0
endfunction