Syntax Error - About your Marble game

Blitz3D Forums/Blitz3D Programming/Syntax Error - About your Marble game

CyBeRGoth(Posted 2003) [#1]
I was thinking of doing a platform game a while ago where you would slip and slide around the levels, just like a ball.

Looking at your code brought up something, is it possible to use the mouse (left / right) to rotate the ball so it faces in a direction, rather than left/right moving the ball in those directions?
As that is the kind of thing i would like in my game but i am unsure about vector maths, I did try playing around with the vectors and stuff, bit to no avail.

cheers


Rob(Posted 2003) [#2]
This is what I'm trying to do at the moment too, as if it were a wheel and not a ball.


CyBeRGoth(Posted 2003) [#3]
Wish I could help but aparently i am worse, even than you! at vector maths :)


Rob(Posted 2003) [#4]
Yep physics is my sucky point. I managed snooker physics (a load of balls) but anything more complex rattles my cage.


CyBeRGoth(Posted 2003) [#5]
Thanks Jeppe :)

http://www.blitzbasic.com/codearcs/codearcs.php?code=856


DH(Posted 2003) [#6]
We're actually doing this in our Globall Project.

I took this from the libraries and edited it. Its very crude, and it isnt plug-n-play, but it gives you an idea on how to do it.

In our game, we have the ability to do straifing along with forward and reverse. I took this out for simplicity.
;===Basic setup of variables
	MouseSpeed# 	= .2
	Accel# 		= 2

;===This is how the hiearchy of the pivots are created 
	MainPlayer 	= createpivot()
	CamPivot1	= createpivot(MainPlayer)
	CamPivot2	= createpivot(CamPivot1)
	BallModel 	= createsphere(8,MainPlayer)
	Camera		= CreateCamera()
	positionentity(Camera,0,0,-10)
	entityparent(Camera,CamPivot2)
	

;====Taken from my player movement function (library) and modified a bit for ease of reading===
	 ;====Rotate camera to mouse position
         ;Get Mouse position then reset Screen Mouse
         MOUX                    = (graphicswidth()/2) - mousex()
         MOUY                    = Mousey() - (graphicsheight()/2)
         Movemouse(graphicswidth()/2,graphicsheight()/2)

         ;===Calculate New Look Angles
         Player\LookX#           = Player\LookX# + (float#(MOUX) * MouseSpeed#)
         Player\LookY#           = Player\LookY# + (float#(MOUY) * MouseSpeed#)
         if Player\LookX# > 359 then Player\LookX# = Player\LookX# - 359
         if Player\LookX# < 0 then Player\LookX# = 359 + Player\LookX#
         if Player\LookY# < -88 then Player\LookY# = -88
         if Player\LookY# > 88 then Player\LookY# = 88

         ;===Rotate Camera to the Looks
         Rotateentity(Player\CamPivot1,0,Player\LookX#,0)
         Rotateentity(Player\CamPivot2,Player\LookY#,0,0)       

	;===Do Movement
	;Calculate Correct 3d Angle of movement
	VelRot# = 359 - KCS_CurveValue#(Player\LookX#)         
	ZMod# = cos(VelRot#)
        XMod# = sin(VelRot#)
	
	;If you want the ball to go in reverse, simply subtract 180 from the velrot and re-run it back through KCS_CurveValue()
	if keydown(Arrow_Up) then moveentity(Player\MainPlayer,XMod# * Accel#,0,ZMod#*Accel#)

	
	;====Do ball roll
 	;reset turnentity
	 RotateEntity Player\BallModel,0,0,0
	 Width# = 360 / (MeshWidth#(Player\BallModel) * 3.14)
	 ;Turn it according to distance traveled
	 Player\BallRollX# = Player\VelZ# * Width#
	 Player\BallRollZ# = -Player\VelX# * Width#
         TurnEntity Player\BallModel,Player\BallRollX#,0,Player\BallRollZ#
	 ;Reset the coordinates of the verticies
  	 RotateMesh Player\BallModel,EntityPitch(Player\BallModel),EntityYaw(Player\BallModel),EntityRoll(Player\BallModel)

;====End of Library extraction



function KCS_CurveValue#(KCS_Angle#)
         if KCS_Angle# > 359 then KCS_Angle# = KCS_Angle# - 359
         if KCS_Angle# < 0 then KCS_Angle# = 359 + KCS_Angle#
         return KCS_Angle#
end function