Yet another problem...

Blitz3D Forums/Blitz3D Beginners Area/Yet another problem...

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

vzlimit# is how fast the ball can be going before it ceases to accelerate any more.


Oh! That explains your "inertia" field, which should be renamed "speed." "Inertia" is synonymous with "mass," and therefore an incorrect (and misleading!) name. Perhaps you were thinking of "momentum," which is mass * speed. In any case, "speed" would be the best name for that field.

Parenting your sphere to its pivot might be what you're looking for?
Graphics3D 800, 600

SeedRnd MilliSecs()

;CONSTANTS

Const leftkey = 203, rightkey = 205, upkey = 200, downkey = 208
Const spacebar = 57, enter = 28

Const gravity# = -.04

;TYPES

Type sphere

	Field shape
	Field pivot
	Field vzlimit#
	Field collision
	Field slowdown#
	Field inertia#
	
End Type

light = CreateLight()
PositionEntity light, 0, 0, 0



camera = CreateCamera()

PositionEntity camera, 10, 5, 0

Global sphere.sphere = New sphere

	sphere\pivot = CreatePivot()
	sphere\shape = CreateSphere(8, sphere\pivot)
	sphere\collision = 1
	sphere\vzlimit# = 1
	sphere\slowdown# = .02
	sphere\inertia# = 0
	
	EntityType sphere\pivot, sphere\collision
	
	EntityType sphere\shape, sphere\collision
	ScaleEntity sphere\shape, .85, 1, 1

	spheretex = LoadTexture("C:\Program Files\Blitz3D\Media\geometricks_models\british-tadpole\btadpole.jpg")
	ScaleTexture spheretex,.125,.25
	RotateTexture spheretex, 90

	EntityTexture sphere\shape, spheretex


	RotateEntity sphere\shape, 0, 0, 0

ground = CreatePlane()
PositionEntity ground, 0, -1, 0

Global groundcollision = 2

EntityType ground, groundcollision
EntityTexture ground, spheretex

cube = CreateCube()
PositionEntity cube, 0, -5, 30
RotateEntity cube, 45, 0, 0
ScaleEntity cube, 5, 5, 5
EntityType cube, groundcollision

Collisions sphere\collision, groundcollision, 2, 2


SetBuffer BackBuffer()



While Not KeyDown(1)
	PointEntity camera, sphere\shape
	
	move()
	
	UpdateWorld
	RenderWorld
	
	Text 0, 0, "Onscreen Triangles: " + TrisRendered()
	Text 0, 10, "Player's Y Coordinates: " + EntityY(sphere\shape)
	Text 0, 20, "Pivot's Y Coordinates: " + EntityY(sphere\pivot)
	
	Flip
	
	Delay 15
Wend

Function move()
	If KeyDown(rightkey)
		TurnEntity sphere\pivot, 0, -5, 0
	EndIf
		
	If KeyDown(leftkey)
		TurnEntity sphere\pivot, 0, 5, 0
	EndIf	
	
	If KeyDown(upkey) Or KeyDown(downkey)
		If KeyDown(upkey)
			If sphere\inertia# < 1.1
				sphere\inertia# = sphere\inertia# + .1
			EndIf
		EndIf
		If KeyDown(downkey)
			If sphere\inertia# > -1.1
				sphere\inertia# = sphere\inertia# - .1
			EndIf
		EndIf
	Else
		If sphere\inertia# < 0
			sphere\inertia# = sphere\inertia# + sphere\slowdown#
		Else
			sphere\inertia# = sphere\inertia# - sphere\slowdown#
		EndIf
		If sphere\inertia# > -.06 And sphere\inertia# < .06
			sphere\inertia# = 0
		EndIf
	EndIf
		
	If sphere\inertia# > sphere\vzlimit#
		sphere\inertia# = sphere\vzlimit#
	ElseIf sphere\inertia# < -sphere\vzlimit#/2
		sphere\inertia# = -sphere\vzlimit#/2
	EndIf
	
	TurnEntity sphere\shape, sphere\inertia#*40, 0, 0
	MoveEntity sphere\pivot, 0, 0, sphere\inertia#
	
End Function


There were a bunch of examples of realistic-looking ball rolling posted somewhere on this site a year or so ago. One of them was rediculously simple and elegant. I'd recommend searching the forums and possibly the code archives for "rolling ball" or similar.