Ok I am making my own scripts. And in 3rd person view my model's legs go through the floor. Also the camera tilts too much the right and left to much when you turn in 3rd person. Ok here's my code.
code:
////////////////////////////////////////////////////////////////////////////
//Defines
//Pointers
Entity* MainChar;
//Variables
Var B; //misc variable stores infomation that isn't needed for long
Var Player_Move_State = 0; // 0 - Standing, 1 - Walking, 2 - Falling
Var Cam_Mode = 0; // 0 - First Person, 1 - 3rd Person
Var Cam_Tilt = -30; // Camera tilt in 3rd person view
Var First_Cam_Tilt = 0; // Camera tilt in 1st person view set by the player
Var Max_Cam_Tilt_Up = 70; // How far the camera can tilt in 1st person view
Var Max_Cam_Tilt_Down = -70;
Var EyeHeight = 10;
//Vectors
Var Cam_Dist[3]; //Distance away from player in 3rd person view
Var force[3];
Var dist[3];
Var Friction;
////////////////////////////////////////////////////////////////////////////
Function ToggleCamMode()
{
If(Cam_Mode == 0) // If camera mode is first person change to 3rd person
{
Cam_Mode = 1;
}
Else // If camera mode is 3rd person change to first person
{
Cam_Mode = 0;
}
}
////////////////////////////////////////////////////////////////////////////
Function Increase_Cam_Tilt()
{
If (First_Cam_Tilt < Max_Cam_Tilt_Up)
{
First_Cam_Tilt += 5;
}
}
////////////////////////////////////////////////////////////////////////////
Function Decrease_Cam_Tilt()
{
If (First_Cam_Tilt > Max_Cam_Tilt_Down)
{
First_Cam_Tilt -= 5;
}
}
////////////////////////////////////////////////////////////////////////////
Function Reset_Cam_Tilt()
{
First_Cam_Tilt = 0;
}
////////////////////////////////////////////////////////////////////////////
Function SmartCam()
{
Cam_Dist.x = 100;
Cam_Dist.y = 100;
Cam_Dist.z = 100;
While(Cam_Mode == 0)
{
Camera.Genius = MainChar;
Camera.X = MainChar.x;
Camera.Y = MainChar.y;
Camera.Z = MainChar.z + EyeHeight; //player.min_z;
Camera.pan = MainChar.Pan;
Camera.tilt = 0 + First_Cam_Tilt;
wait(1);
}
While(Cam_Mode == 1)
{
Camera.Genius = Null;
Camera.X = MainChar.x + Cam_Dist.x;
Camera.Y = MainChar.y + Cam_Dist.y;
Camera.Z = MainChar.z + Cam_Dist.z; //player.min_z
Camera.pan = MainChar.Pan;
Camera.tilt = Cam_Tilt;
wait(1);
}
}
////////////////////////////////////////////////////////////////////////////
Action Player_Walk
{
MainChar = Me;
while(1)
{
force.pan = -10 * key_force.x;
my.skill14 = time*force.pan + max(1-time*0.7,0)*my.skill14;
my.pan += time * my.skill14;
vec_set(temp,my.x);
temp.z -= 4000;
trace_mode = ignore_me+ignore_sprites+ignore_models+use_box;
result = trace(my.x,temp);
if (result > 5) //Player in the air?
{
force.x = 0;
force.y = 0;
force.z = -5; //gravity force
friction = 0.1; //air friction
}
else //on or near ground
{
force.x = 10 * key_force.y;
force.y = 0;
friction = 0.7; //ground friction
}
my.skill11 = time*force.x + max(1-time*friction,0)*my.skill11;
my.skill13 = time*force.z + max(1-time*friction,0)*my.skill13;
dist.x = time * my.skill11; // distance ahead
dist.y = 0;
dist.z = time * my.skill13; // distance down
move_mode = ignore_passable + glide;
b = ent_move(dist,nullvector); // move the player
If (b != 0) //Player is moving find out why
{
If (key_force.x != 0) //Player is using the arrow keys to move
{
Player_Move_State = 1; //Player is walking
}
If (key_force.y != 0) //Player is using the arrow keys to move
{
Player_Move_State = 1; //Player is walking
}
Else //Player isn't using the arrow keys so the player must be falling
{
Player_Move_State = 2; //Player is falling
}
}
If (b == 0) //Player is standing still
{
Player_Move_State = 0;
}
Player_Animation(); //Animate character
SmartCam();
wait(1);
}
}
////////////////////////////////////////////////////////////////////////////
Function Player_Animation()
{
//If player is walking make the model go though walking animation
While(Player_Move_State == 1)
{
ent_cycle("walk", my.skill20);
my.skill20 += 1 * time;
If (my.skill20 > 100)
{
my.skill20 = 0;
ent_playsound (me, thud, SoundFXVolume); //Play step sound
}
wait(1);
}
}
////////////////////////////////////////////////////////////////////////////
On_home Reset_Cam_Tilt;
On_pgup Increase_Cam_Tilt;
On_pgdn Decrease_Cam_Tilt;
On_tab ToggleCamMode;
////////////////////////////////////////////////////////////////////////////