Sorry to bump this thread up, but I didn't think I should create a new
topic for the same thing...
Anyways, Webber's code works very well, but I'm having one annoying problem,
when I press the "w" key my character turns and starts to walk towards the camera,
and if I press the "s" button, my character still walks towards the camera,
also the wobble glitch is still somewhat there, especially when I press the spacebar to jump
can anyone help me?
heres my entire code:
Rem Project: "Instinct"
Rem Created: Sunday November, 27 2011
Rem ***** Main Source File *****
Sync on
Sync rate 60
backdrop on
load dll "user32.dll",1
Sw=call dll(1,"GetSystemMetrics",0)
Sh=call dll(1,"GetSystemMetrics",1)
delete dll 1
set display mode Sw,Sh,32,1
maximize window
hide mouse
set cursor 0,0
Yourcharacter = 1
SpeedofYourCharacter# = -0.07
CameraRadius# = 1
CAX# = 25
CAY# = 0
load object "Twitch_animated.x",1
set object speed 1,120
loop object 1,1,20
scale object 1,32,32,32
load image "Twitch_2easyuv.png" ,2
texture object 1,2
load object "level_alpha1.x" ,2
position object 2,2,0,3
sc_setupcomplexobject 2,1,1
load object "levellayout.x" ,3
position object 3,0,-8,0
scale object 3,500,500,500
load image "skybox_texture.png", 1
load object "skybox.x" ,4
scale object 4,1000,1000,1000
texture object 4,1
Set object ambient 4, 0
set object light 4, 0
load effect "Toon.fx",1,0
set object effect 1,1
vec = make vector4 (1)
set object effect 2,1
rem main loop
do
MMX = MouseMoveX()
MMY = MouseMoveY()
Up = 0
Down = 0
Right = 0
Left = 0
rem get previous position
oldx# = object position x(1)
oldy# = object position y(1)+0.4
oldz# = object position z(1)
rem object controls
if keystate(17) = 1 then move object 1,-0.07: LOOP OBJECT 1,50,90
if keystate(30) = 1 then y=wrapvalue(y-1)
if keystate(31) = 1 then move object 1,0.07
if keystate(32) = 1 then y=wrapvalue(y+1)
yrotate object 1,y
if (ScanCode() = 0) then loop object 1, 1,20
rem get updated positions
X# = object position x(1)
Y# = object position y(1)+0.4
Z# = object position z(1)
if keystate(17)=1 or keystate(31)=1 or keystate(32)=1 or keystate(30)=1
if keystate(17)=1
FollowCharacterAngle# = CAY#
inc CameraRadius#, .1
if CameraRadius# > 7 then CameraRadius# = 7
ENDIF
if keystate(31)=1
FollowCharacterAngle# = CAY#+180
dec CameraRadius#, .1
if CameraRadius# < 4 then CameraRadius# = 4
ENDIF
if keystate(32)=1 then FollowCharacterAngle# = CAY#+90
if keystate(30)=1 then FollowCharacterAngle# = CAY#-90
if keystate(17)=1 and keystate(32)=1 then FollowCharacterAngle# = CAY#+45
if keystate(17)=1 and keystate(30)=1 then FollowCharacterAngle# = CAY#-45
if keystate(31)=1 and keystate(32)=1 then FollowCharacterAngle# = CAY#+135
if keystate(31)=1 and keystate(30)=1 then FollowCharacterAngle# = CAY#-135
Rem Corrects all angles (0-360)
if FollowCharacterAngle# < 0 then inc FollowCharacterAngle#,360
if YourCharacterAngle# < 0 then inc YourCharacterAngle#,360
if FollowCharacterAngle# > 360 then dec FollowCharacterAngle#,360
if YourCharacterAngle# > 360 then dec YourCharacterAngle#,360
Rem Gets the shortest angle distance
AngDistance# = FollowCharacterAngle#-YourCharacterAngle#
if AngDistance# < 0 then inc AngDistance#,360
`if AngDistance# > 360 then dec AngDistance#,360
Rem Gets the Character's new angle in the correct direction
if AngDistance# <= 180 then inc YourCharacterAngle#,7
if AngDistance# > 180 then dec YourCharacterAngle#,7
Rem Removes wobble glitch
if YourCharacterAngle# < FollowCharacterAngle#+8 and YourCharacterAngle# > FollowCharacterAngle#-8 then YourCharacterAngle#=FollowCharacterAngle#
rotate object YourCharacter,0,YourCharacterAngle#,0 `Rotates the player
move object YourCharacter,SpeedOfYourCharacter# `Moves the player
endif
if CameraRadius# > 4.3 then dec CameraRadius#,.05
if CameraRadius# < 4.3 then inc CameraRadius#,.03
Rem makes the camera focus on the character
point camera 0,object position x(1),object position y(1),object position z(1)
CAY# = Camera Angle Y(0) `Gets the cameras new Y angle
Rem rotate the camera using the mouse
inc CAY#,MMX
inc CAX#,MMY
Rem put a limit on the cameras X angle
if CAX# < 5 then CAX# = 5
if CAX# > 80 then CAX# = 80
Rem Positions and rotates the camera
position camera 0,object position x(1),object position y(1),object position z(1)
rotate camera 0,CAX#,CAY#,0
move camera 0,-CameraRadius#
sync
rem add gravity
dec speedY#,.2
inc y#,speedY#
rem check for collision
collide = sc_sphereslide(0,oldx#,oldy#,oldz#,X#,Y#,Z#,0.4,0)
if collide>0
rem get new positions of player
X# = sc_getcollisionslideX()
Y# = sc_getcollisionslideY()
Z# = sc_getcollisionslideZ()
nY# = sc_getcollisionnormalY()
if nY#>.9
speedY# = 0
if spacekey() then speedY# = .99
endif
endif
rem update player positions
position object 1,x#,y#-0.4,z#
sync
loop
delete memblock 1
and heres a picture:
http://i250.photobucket.com/albums/gg258/sazex/cameracontrolprob.png
sazex