Hi,
About "how to program the player" is quite hard to tell, as it depends a lot on your game genre, however, you just need how to do the following in Lite-C:
- Moving the player
- Setting the camera position
- Getting input from the player
These are the most basic things you need to know about, for making your player - more stuff could be added later.
- Moving the playerThis can be done in a very simple way: simply by changing the x, y and z position of the player. However, doing it that way would allow you to ignore all obstacles and walk straight through anything, as it does not involve collission detection.
Instead, you should be using c_move (check the manual) to move the player, like this:
action player_script()
{
while(my)
{
c_move(my,vector(my.skill1 * time_step,0,0),nullvector,IGNORE_PASSABLE + GLIDE);
wait(1);
}
}
I am using "while(my)" to make the loop continue as long as the "my"-entity exists (you could as well use "while(1)" if you are not removing your player somewhere in the code).
The c_move command is moving the "my"-entity (the player) in the direction that the entity is facing, with a speed of "my.skill1 per second", and passable objects are ignored (you can move right through those). Additionally, the "GLIDE" flag allows you to glide along walls, but you'll figure out what that means by experimenting.
All you need to do now, is set skill1 of the entity with the player script, and it will move.
- Setting the camera positionHow you want to set the camera depends on your game - it could be first-person, third-person, isometric, or something else. Let's add the code for a first-person camera:
action player_script()
{
while(my)
{
camera.x = my.x;
camera.y = my.y;
camera.z = my.z + 50;
camera.pan = my.pan;
c_move(my,vector(my.skill1 * time_step,0,0),nullvector,IGNORE_PASSABLE + GLIDE);
wait(1);
}
}
This sets the camera at the player's position (so don't do this if you assign this action to multiple entities!), and adjusts the height to be 50 quants above the player - play a bit with this value.
Then the camera is set to face the same way as the player model (using the pan-axis).
You could set the player entity invisible if you like by using "my.flags |= INVISIBLE".
- Getting input from the playerFor getting input from the keyboard keys, you can check e.g. "key_w" to see whether W was pressed - if it returns 0, the key is not pressed, and if it returns 1, it's pressed. For using the mouse to look around, you need to use mouse_force.x and y:
action player_script()
{
my.flags |= INVISIBLE;
while(my)
{
camera.x = my.x;
camera.y = my.y;
camera.z = my.z + 50;
camera.pan = my.pan;
if(key_w)
{
my.skill1 = 10;
}
else
{
my.skill1 = 0;
}
my.pan -= mouse_force.x;
camera.tilt += mouse_force.y;
c_move(my,vector(my.skill1 * time_step,0,0),nullvector,IGNORE_PASSABLE + GLIDE);
wait(1);
}
}
This is by far not the most elegant way of using "key_w", but it is probably the most simple in this case: if W is pressed, the speed is set to 10, and if it's not pressed, the speed is set to 0, which means no movement.
As camera pan is set to the same as the player's pan, you can as well just turn the player (using pan) instead of only the camera, but it doesn't make a difference as long as we don't see the player. The player should keep a constant tilt value though, and you might want to limit camera.tilt to be between e.g. -80 and 80 degrees (check out "clamp" in the manual).
I didn't test the code and wrote it in quite a hurry, but it should give you an idea of how to get started. Also remember, that the manual is one of the best resources available whenever you need coding help
![wink wink](/ubb7/images/graemlins/default_dark/wink.gif)
Oh, and I know that this wasn't the only thing you asked about, but I don't know any other tutorials which might suit your needs
![frown frown](/ubb7/images/graemlins/default_dark/frown.gif)
But I hope you can use this in any way
![grin grin](/ubb7/images/graemlins/default_dark/grin.gif)