Posted: 12th Aug 2007 6:26
That is true, but the difficulty lies in determining the proper amount of "reverse" force to apply. Since the forward motion is applied and then wears off gradually, I suppose you could do a check for the level of forward force being applied at the time the key is released. Doing so, though, runs the risk of having the character move a bit backward after the key is released, almost like he's bouncing off of a wall or something.

It sounds all the way around like Dark Physics is better for this.
Posted: 12th Aug 2007 11:23
You also need to know WHEN to apply this force, eg have to calculate where you want to end up and then how long that force needs to be applied for,

Unless you stored the force being exerted and when a key was being pressed you exert the force that's being exerted at that time in the application,
Posted: 12th Aug 2007 22:39
The only way I can think of doing it is like this ... (without getting into specific code since I don't have anything handy and I'm not that familiar with actually getting values FROM Newton as opposed to just telling it what to do)

1. Apply the forces necessary to propel the body in a direction that the user wants ... this is easier than it sounds though, since my program is a third-person RPG "sandbox" kind of game, where you can go in virtually any direction. With Newton, even if you apply a purely forward-moving force, little things like polygon collision would apply unseen, subtle forces that could (and do) wreak havoc on the player body. (hence the spinning out stuff)

2. Check for the values of ALL forces being applied to the body at the moment the player wants to stop or switch direction and store those values in their respective variables. To do this, I would think that the most logical approach would be to get the values and check to see if they are positive or negative.

3. Once all the values are established and their values as positive or negative numbers are also stored, the program could take the absolute values of the negative numbers and convert the positive numbers to negative numbers and store them all in new variables.

4. Lastly, the program should apply ALL the new variable forces against the player body in order to nullify the present forces at work and set them all to zero.

There are a few problems with this, however.

Newton doesn't apply sudden forces very well. It tends to apply them gradually in an attempt to look more natural. Thus, when you actually hit the forward key to move, Newton doesn't just suddenly apply 50 units of force to your character to move it quickly. Rather, it applies that force gradually to give your body the illusion of inertia.

This means that applying exact opposite forces in order to stop the character in place would be done gradually as well, resulting in not only a gradual slowdown of the character rather than a sudden stop, but also the potential for causing even more confusion by either forcing the character model to move backwards or by applying forces that would end up with further spinning out of the character model.

I can't figure out any way to reasonably do it ... the FPS demo seems to handle it better, but I think Newton has a separate setup for camera bodies.
Posted: 12th Aug 2007 22:42
Just one more little sidenote: I also tried making my character's mass as low as possible, at one point even setting it to zero, in the hope that the forces might be applied more like DarkBasic applies them ... nothing worked. If anything, it only made the character spin out even worse.
Posted: 12th Aug 2007 22:54
I have some problems too with characters, but I have some interesting results so far. The first thing to do is to make an Up joint on the body. An other important thing : the body and the visual object must'nt be linked, so the body can have some strange rotations wihtout affecting the object (you just need to position your model yourself ).
Now, the easiest way to move the character is to use NDB_NewtonBodySetVelocity, but the problem is that your character will push any rigid body without any problems.
Using NDB_BodySetForceGlobal will prevent your character pushing some big bodies, but it gives you less control (because of the friction and other stuff like that).
Posted: 13th Aug 2007 1:20
Can you upload some demo code to illustrate what you're talking about? It sounds interesting ... basically what you're talking about is not linking the character rigid body with the character 3d model ... but the thing is, it seems to me at least, that while the character rigid body may be spinning out of control, the 3d model itself will still give the appearance of being stable.

This could have its own consequences, though, especially if you're doing polygon collision. For example, if you're trying to do bullet collision and you've got a headshot system, the detection could be way off depending on the position of the rigid body. Or, if you have your character pick up an object like a weapon, you've got a serious problem with collision where that's concerned.
Posted: 13th Aug 2007 12:54
This code shows how to move a perfectly stable object (same resultat as Move Object), but the player as an infinite force, so he can push all the other bodies (even with a huge mass).

+ Code Snippet
`standard DBPro startup code...
sync on
sync rate 60
autocam off

set ambient light 70
set point light 0, 50, 100, -50
set light range 0, 5000

randomize timer()

Type Character
	angle As Float
	body As Integer
	object As Integer
	speed As Float	
EndType
Global player As Character


`Initialize Newton, and create the Newton World.
NDB_NewtonCreate
NDB_SetVector 0.0, -100.0, 0.0
NDB_SetStandardGravity
time# = NDB_GetElapsedTimeInSec()
time# = NDB_GetElapsedTimeInSec()


rem floor object
makeBox(0,-100,0, 1000, 10, 1000, 0)
rem a few random boxes
For b=0 to 20
	s=10+rnd(20)
	makeBox(rnd(200)-100,20+rnd(60),rnd(200)-100, s+rnd(4), s+rnd(4), s+rnd(4), 120+rnd(80))
Next b
rem player object
makeCharacter()
player.speed = 100

Position camera 0,40,-200
Point Camera 0,-60,0

do
	`get the elapsed time since last frame and save into time# variable.	
	time# = NDB_GetElapsedTimeInSec()

	NDB_NewtonUpdate time#
	if controlkey()
		obj = NDB_DebugMakeNewtonObject()
		set object light obj, 0
	else
		obj = 0
	endif

	updateCharacter()
	`update the screen
	sync
	
	if obj <> 0
		delete object obj
	endif	
	

loop
` Destory the Newton world, clearing up any memory that was allocated.	
NDB_NewtonDestroy
end

Function updateCharacter()

	NDB_NewtonBodyGetVelocity player.body	
	If UpKey()
		NDB_SetVector player.speed * sin(player.angle), NDB_GetVector_Y(), player.speed * cos(player.angle)
	Else
		NDB_SetVector 0, NDB_GetVector_Y(), 0
	EndIf
	NDB_NewtonBodySetVelocity player.body
	player.angle = wrapvalue(player.angle + (RightKey()-Leftkey())*4)

	rem object update
	NDB_BodyGetPosition player.body
	Position object player.object, NDB_GetVector_X(), NDB_GetVector_Y(), NDB_GetVector_Z()
	rotate object player.object, 0, player.angle, 0
EndFunction

Function makeCharacter()
	col = NDB_NewtonCreateBox( 40, 40, 40 )
	body = NDB_NewtonCreateBody( col )
	NDB_BuildMatrix 0.0, 0.0, 0.0, 0, 0, 0
	NDB_NewtonBodySetMAtrix body
	NDB_CalculateMIBoxSolid 100, 40, 40, 40
   NDB_NewtonBodySetMassMatrix Body, 100
   NDB_BodySetGravity Body, 1
	NDB_NewtonReleaseCollision Col
	NDB_NewtonBodySetAutoFreeze body, 0
	NDB_SetVector 0,1,0
	joint = NDB_NewtonConstraintCreateUpVector(body)
	NDB_NewtonBodySetMaterialGroupID body, mplayer
	NDB_NewtonBodySetLinearDamping body,0.0

 	obj = FreeObject()
   Make object box obj, 40, 40, 40
   position object obj, 0, 0, 0
   color object obj, GetColor()
   set object ambience obj, 50
   
	player.body = body
	player.object = obj
	
EndFunction character


Function makeBox(x#,y#,z#, sx#, sy#, sz#, mass#)
	col = NDB_NewtonCreateBox( sx#, sy#, sz# )
	body = NDB_NewtonCreateBody( col )
	NDB_BuildMatrix 0.0, 0.0, 0.0, x#, y#, z#
	NDB_NewtonBodySetMAtrix body
	If mass# > 0
	 	NDB_CalculateMIBoxSolid mass#, sx#, sy#, sz#
	   NDB_NewtonBodySetMassMatrix Body, mass#
	    NDB_BodySetGravity Body, 1
	EndIf
	NDB_NewtonReleaseCollision Col
 	obj = FreeObject()
   Make object box obj, sx#, sy#, sz#
   position object obj, x#, y#, z#
   color object obj, GetColor()
   set object ambience obj, 50
   NDB_BodySetDBProData Body, obj
   NDB_NewtonBodySetDestructorCallback Body
   NDB_NewtonBodySetMaterialGroupID body, mfloor
EndFunction body

function FreeObject()
	repeat
		inc i 
		if object exist(i)=0 then found=1
	until found
endfunction i
function GetColor()
	repeat
		r = rnd(1)*255
		g = rnd(1)*255
		b = rnd(1)*255
	until r<>0 or g<>0 or b<> 0
	color =  rgb(r,g,b)
endfunction color
delete memblock 1

I think I'll use a function like the one in the fps exemple, it's not as stable, but rather good.


About bullet collisions on a character, I think it's not a good idea to rely only on a rigid body (especially if your character is animated). This is what I want to do : first, we have to check the collision with the character bounding box, then, if the bullet hits the box, we have to position some boxes/cylinders on each bone of the model, and finally restart the raycasting with the new boxes. This allows you to have an accurate and rather fast collision detection. Once done, it's pretty easy to have a rag doll using a force to simulate the bullet impact.
Posted: 16th Aug 2007 4:44
Well, I just purchased Dark Physics and I've got this to say:

If you haven't got it, get it. It's not that expensive considering all of the new features that you get after installing it. It does things that Newton takes YEARS to implement, such as cloth effects (including making cloth tearable) and water/liquid/slime/particles, you name it.

Anyway, I installed Dark Physics and literally, in THREE MINUTES I have completely implemented the system that I have spent all summer working on with Newton. That's right - three months of work boiled down to three minutes and about fifteen lines of code.

Dark Physics also applies local and global forces to the objects, and can even automatically set up polygon collision for terrain models, such as mine. It has a separate character controller which automatically solves the "upright joint" problem and handles collision with other objects properly.

I LOVE DARK PHYSICS.

At the risk of sounding like a commercial, go get it. It's absolutely worth it.
Posted: 16th Aug 2007 10:42
I may just do that...if I had money?
Posted: 16th Aug 2007 12:46
I finally used the fps exemple for my characters, and now, I have a nice working character controller (it's not complete but the characters can move and jump).