Hi all,
I'm trying to make a ball roll along the ground and when I jump, it compresses first before actually jumping. So in other words, before it jumps, I scale its height (Y axis) by half and when it is in the air, I restore its height.
I also want my ball to roll while moving left and right. However, this effects my scaling since the scale is in relations to the ball's local Y axis and since it rolls, the Y axis changes.
Here is my code thus far:
SET DISPLAY MODE 1024, 768, 32
SYNC ON
SYNC RATE 60
`SETTING UP CAMERA
GLOBAL camerax AS INTEGER = 0
GLOBAL cameray AS INTEGER = 30
GLOBAL cameraz AS INTEGER = -30
MAKE CAMERA 1
POSITION CAMERA 1, camerax, cameray, cameraz
POINT CAMERA 1, 0, 15, 0
`SETTING UP PLAYER
GLOBAL player_speed AS FLOAT = 0.5
GLOBAL roll AS INTEGER = 0
GLOBAL jump AS INTEGER = 0
GLOBAL jump_height AS FLOAT = 0
GLOBAL jump_delay AS INTEGER = 0
`The Player's Core
MAKE OBJECT SPHERE 9999, 3
POSITION OBJECT 9999, 0, 10, 0
SC_SETUPOBJECT 9999, 1, 1
HIDE OBJECT 9999
`The Player's Shell
MAKE OBJECT SPHERE 999901, 3
POSITION OBJECT 999901, 0, 10, 0
`The sub-player that the camera looks at
GLOBAL camera_lookatx AS INTEGER = 0
GLOBAL camera_lookaty AS INTEGER = 10
GLOBAL camera_lookatz AS INTEGER = 10
MAKE OBJECT SPHERE 999902, 3
POSITION OBJECT 999902, camera_lookatx, camera_lookaty, camera_lookatz
HIDE OBJECT 999902
`SETTING UP LEVEL
MAKE OBJECT CUBE 1, 1
POSITION OBJECT 1, 0, 0, 0
SC_SETUPOBJECT 1, 2, 2
SC_ALLOWOBJECTSCALING 1
SCALE OBJECT 1, 5000, 100, 100
MAKE OBJECT CUBE 2, 1
POSITION OBJECT 2, 50, 5, 0
SC_SETUPOBJECT 2, 2, 2
SC_ALLOWOBJECTSCALING 2
SCALE OBJECT 2, 5000, 100, 100
DO
`REFRESHING LOOK AT POINT, PLAYER'S SHELL AND CAMERA
POSITION OBJECT 999902, OBJECT POSITION X(9999), OBJECT POSITION Y(9999) + 10, OBJECT POSITION Z(9999) + 10
POSITION OBJECT 999901, OBJECT POSITION X(9999), OBJECT POSITION Y(9999), OBJECT POSITION Z(9999)
POSITION CAMERA 1, OBJECT POSITION X(9999), cameray, cameraz
POINT CAMERA 1, OBJECT POSITION X(999902), camera_lookaty, OBJECT POSITION Z(999902)
`WORLD FUNCTIONS
gravity()
`PLAYER FUNCTIONS
ZROTATE OBJECT 999901, roll
controls()
`UPDATING OBJECTS
SC_UPDATEOBJECT 9999
FOR n = 1 to 2
SC_UPDATEOBJECT n
NEXT n
`TECHNICAL INFORMATION
TEXT 0, 0, "Jump: " +str$(jump)
TEXT 0, 15, "Roll: " +str$(roll)
SYNC
LOOP
FUNCTION gravity()
IF jump = 0 AND SC_GROUPCOLLISION (9999, 2) = 0
MOVE OBJECT DOWN 9999, player_speed
ENDIF
ENDFUNCTION
FUNCTION controls()
`MOVING PLAYER LEFT AND RIGHT
IF RIGHTKEY() = 1
MOVE OBJECT RIGHT 9999, player_speed
DEC roll, 5
ENDIF
IF LEFTKEY() = 1
MOVE OBJECT LEFT 9999, player_speed
INC roll, 5
ENDIF
`ALLOWING THE PLAYER TO JUMP
IF SPACEKEY() = 1 AND jump = 0 AND SC_GROUPCOLLISION(9999, 2) > 0
jump_height = OBJECT POSITION Y(9999) + 8
jump = 1
SCALE OBJECT 999901, 125, 50, 100
POSITION OBJECT 9999, OBJECT POSITION X(9999), OBJECT POSITION Y(9999) - 0.5, OBJECT POSITION Z(9999)
jump_delay = 2
ENDIF
IF jump = 1 AND jump_delay = 0
MOVE OBJECT UP 9999, player_speed
IF OBJECT POSITION Y(9999) = jump_height
jump = 0
ENDIF
SCALE OBJECT 999901, 100, 100, 100
ENDIF
IF jump_delay > 0
DEC jump_delay, 1
ENDIF
ENDFUNCTION
In the jump code, you can see the compression via the object scaling. In the movement code, you can see variable "roll" that controls the ball rolling (which is refreshed in the DO LOOP).
So how do I keep the ball rolling, but be able to compress it always on its Y axis. I COULD reset the rotation of the ball before compressing, but I want to texture the ball so that it looks like a basketball, or a beachball and resetting the ball's rotation will be noticeable.
EDIT: Changed the code to my latest. Sorry about that.