I've had a search through the forums and looked through the newton demos but I can't find a solution to my current problem so I apologise if this has already been answered and I've just missed it.
I'm making a small mini golf game and I have a series of ramps in my level (they're just boxes that I've rasied one edge of in 3D Canvas).However, when I fire a sphere up the ramp, if it doesn't make it to the top it just gets stuck to the mesh and doesn't roll back down the slope. If the ball makes it to the top of the ramp and bounces off a wall then it rolls quite happily down the ramp. It only happens if a ball makes it half way up.
I use the following code to create the static mesh:
function nwt_Make_Static_Mesh(obj_no)
if object exist(obj_no)
obj_x# = object position x(obj_no)
obj_y# = object position y(obj_no)
obj_z# = object position z(obj_no)
col = ndb_NewtonCreateTreeCollision(obj_no)
mesh = ndb_NewtonCreateBody(col)
ndb_BuildMatrix 0.0,0.0,0.0,obj_x#,obj_y#,obj_z#
ndb_NewtonBodySetMatrix mesh
ndb_BodySetDBProData mesh,obj_no
ndb_NewtonReleaseCollision col
endif
endfunction mesh
Then I use the following code to fire the ball (for which I've created a dynamic newton object using code similar to the one above). I use the following function to fire the ball:
function nwt_Push_Object(obj_no,distance#)
obj_x# = object position x(obj_no) : obj_y# = object position y(obj_no) : obj_z# = object position z(obj_no)
ang_x# = object angle x(obj_no) : ang_y# = object angle y(obj_no) : obj_z# = object angle z(obj_no)
object_direction_x# = newxvalue(obj_x#,ang_y#,distance#)
object_direction_z# = newzvalue(obj_z#,ang_y#,distance#)
object_direction_y# = newyvalue(obj_y#,ang_x#,distance#)
vel_x# = object_direction_x# - obj_x#
vel_y# = object_direction_y# - obj_y#
vel_z# = object_direction_z# - obj_z#
ndb_SetVector 1,vel_x#,vel_y#,vel_z#
name = ndb_GetBody(obj_no)
ndb_NewtonBodySetVelocity name
endfunction
I then use the following code to run the update the ball movement:
no_move = 0
`setup physics object
nwt_make_dynamic_sphere(1)
`apply force to dynamic object
nwt_push_object(1,current_power)
time# = ndb_GetElapsedTimeInSec()
time# = ndb_GetElapsedTimeInSec()
`setup movement flags
flag_x = 0
flag_y = 0
flag_z = 0
`run physics simulation
repeat
`store last ball position
last_ball_x# = object position x(1)
last_ball_y# = object position y(1)
last_ball_z# = object position z(1)
`update physics
time# = ndb_GetElapsedTimeInSec()
ndb_NewtonUpdate time#
`store current ball position
current_ball_x# = object position x(1)
current_ball_y# = object position y(1)
current_ball_z# = object position z(1)
`compare the difference between the object's current and last position
if current_ball_y# < -20.0
player_fallen = 1
no_move = 1
else
if current_ball_x# = last_ball_x# and current_ball_y# = last_ball_y# and current_ball_z# = last_ball_z#
no_move = 1
endif
endif
point camera current_ball_x#,current_ball_y#,current_ball_z#
difference_x# = current_ball_x# - last_ball_x#
difference_y# = current_ball_y# - last_ball_y#
difference_z# = current_ball_z# - last_ball_z#
if difference_x# < 0.005 and difference_x# > -0.005 then flag_x = 1
if difference_y# < 0.005 and difference_y# > -0.005 then flag_y = 1
if difference_z# < 0.005 and difference_z# > -0.005 then flag_z = 1
if flag_x = 1 and flag_y = 1 and flag_z = 1
no_move = 1
endif
`calculate the new sky box position in front of the camera
new_sky_box_x# = newxvalue(camera position x(),camera angle y(),25.0)
new_sky_box_z# = newzvalue(camera position z(),camera angle y(),25.0)
`rotate the sky box
set object to camera orientation 300
position object 300,new_sky_box_x#,camera position y()-20,new_sky_box_z#
`scroll the sky box texture
scroll object texture 300,0.005,0.005
sync
until no_move = 1
I've created the static mesh before this section of the code. I'll post the full source if I have to but it's still in a fairly rough state and it's a little awkward to get to the correct section (in order to see the problem). I know it isn't the model that is the problem because I've tried several different models and they all suffer from the same issue.
I've also tried setting up different materials and adjusting friction values to see if that is the problem (didn't help), I've tried adjusting the gravity and mass of the ball (didn't help), I've tried setting the solver and friction models to more realistic modes (didn't help) and I've tried increasing the amount of polygons in the object in order to increase the amount of contact points (that was a vain attempt and needless to say didn't help).
Sorry for the long post but I'm trying to be as thorough as possible in the hopes that someone has the answer.
Thanks,
Adam