Hello again, first of all thank you for putting your time and energy into helping me and possibly other people.
I have a few questions regarding to camera movement.
First some details about the game.
* My game is going to be in a third person view behind the player.
* The radar will be a camera positioned above the player, while being turned to the player/ground.
Question 1 : Camera Collision using sparkys DLL.
The command I'm using to detect collision is:
"SC_RayCastGroup"
Snippet of my RayCast code in the main loop.
I haven't used any variables yet, will do this when the code is fully functional.
If sc_raycastgroup(0,Camera Position X(),Camera Position Y(),Camera Position Z(),object position x(1),object position y(1),object position z(1),1) => 1
move camera 0,sc_getcollisiondistance()+1
Endif
The explanation of the command :
return integer=SC_rayCastGroup ( groupNum, oldx, oldy, oldz, x, y, z, excludeObj )
-groupNum: the group you want to check for collision use 0 for all groups
-oldx...z: the start and end points of the ray to check.
-excludeObj: a single object to exclude from the collision check
returns: the object number collided with first is returned
returns 0 if no collision occured.
I'm using the SC_RayCast(Group) command also to for bullet handling, and it works flawless.
When there's an object between the player and the camera, the camera repositions but still lets parts of the object be seen.
When setting the value of
"move camera 0,sc_getcollisiondistance()+1"
to lets say, 10
"move camera 0,sc_getcollisiondistance()+10"
The camera repositions Distance * framerate wich makes the game unplayable.
I've tried using the SQRT command into a CameraDistance# variable to replace the SC_GetCollisionDistance like this :
CameraDistance# = SQRT( (Object Position X(1)-Camera Position X())^2 + (Object Position Y(1)-Camera Position (Y))^2 + (Object Position Z(1)-Camera Position Z())^2)
If sc_raycastgroup(0,Camera Position X(),Camera Position Y(),Camera Position Z(),object position x(1),object position y(1),object position z(1),1) => 1
move camera 0,CameraDistance# - CameraDistance +1
Endif
This does not work either and gives the same result.
How can I make the camera collision work properly?
Question 2 :
I have set up a second camera :
Camera_Radar = 2
Make camera Camera_Radar
set camera view Camera_Radar,500,500,700,700
Angle = 0
Distance = 0
Height = 200
Smooth = 10
Collision = 0
Do
set camera to follow 2,Player.X,Player.Y,Player.Z,Angle,Distance,Height,Smooth,Collision
point camera 2,player.x,player.y,player.z
Loop
The code I'm using to move my character around using the mouse, and the WASD keys :
(It's from a tutorial)
Rem Store Object angle Y in aY#
aY# = Object angle Y(Player.Object)
Rem get player object position and store in X# and Z#
X# = Object position x(Player.Object)
Z# = Object position z(Player.Object)
Rem get new camera position and store in cZ# and cX#
cZ# = Newzvalue(Z#,aY#-180,100)
cX# = Newxvalue(X#,aY#-180,100)
Set Camera To Follow Player.X,Player.Y,Player.Z,WrapValue(Object Angle Y(1)),100,20,15,0
MMx = MouseMoveX()
Y# = WrapValue(Object Angle Y(1)+MMx)
Yrotate Object 1,Y#
And in a Gosub MovePlayer (From the Sparkys DLL Example)
yrotate object Player.Object,object angle y(Player.Object)+mousemovex()/3.0
if keystate(32)=1 then vx# = vx# + cos(angy#) : vz# = vz# - sin(angy#)
if keystate(30)=1 then vx# = vx# - cos(angy#) : vz# = vz# + sin(angy#)
if keystate(31)=1 then vx# = vx# - sin(angy#) : vz# = vz# - cos(angy#)
if keystate(17)=1 then vx# = vx# + sin(angy#) : vz# = vz# + cos(angy#)
The camera is showing up in game at the specified coordinates on the screen, and it's showing my "character" from top view, wich is good.
However when I use the keys to walk, my camera "flips" around.
My guess is I need to somehow make this camera only follow the player, and not rotate around.
Ideas to help me out, shoot them please.
Also a side question :
I have a Limb in front of the player as weapon aim. It positions randomly to create a "real" effect for weapons not exactly shooting at where you aim.
PrimaryWeapon.SpreadX = RND(5)
PrimaryWeapon.SpreadY = RND(5)
It's working but one little problem there.
If you slice the screen in half over the heigth and width you'll have 4 "squares", the limb only randomly places in the top right squares, or are my eyes betraying me?
Rem - Weapon Range (Limb Offset)
If Player.ActivePrimary = 1
WeaponRange = PrimaryWeapon.Range
offset limb 1,1,PrimaryWeapon.SpreadX,PrimaryWeapon.SpreadY,WeaponRange
Endif
If Player.ActiveSecondary = 1
WeaponRange = SecondaryWeapon.Range
Offset limb 1,1,SecondaryWeapon.SpreadX,SecondaryWeapon.SpreadY,WeaponRange
Endif
Thanks again for your time, I will be posting a video tonight showing my problems to make them more clear.
Also any comments to create my ideas in a different way are much appreciated.
Watch my problems in High Def on
http://www.youtube.com/watch?v=EkEG1qSIGz0&feature=youtu.be
Hi 5!