From ground up?

Ah, well, okay

You wan't your entity to move and you want gravity for it. The two instructions we need for that are c_move and c_trace (besides some others).
Let's do the "move-part" first and have a look at the instruction:

Code:

c_move(entity,relvec,absvec,move_mode);



Okay, so we have the instruction-name c_move and four things to pass, which are named "entity", "relvec", "absvec" and "move_mode" here. The name isn't really important, but in this case they give us an idea what exactly c_move needs.

The first thing is "entity". That's an easy one, isn't it? Of course the engine needs to know which entity shall be moved. So we need a pointer which points to said entity and moves it afterwards. We can use "player" when we want to move the player (at least when "player" points to the player ) or, which will be of more use now, "me" and "you". "me" is a special, predefined pointer. In our action, it points to the entity which uses the action, so we can use me here.

The second thing is "relvec". As the last part "vec" suggest, we need a vector for it. In case you don't know what a vector is, I'll explain the basics now. If you can speak german, you might want to take a look here.
A vector basically contains three values. What they represent depends on it's usage (there are "colorvectors", too, then it's three values represent red, green and blue), in math and in our example they are the values "X", "Y" and "Z". Now, chances are that you already heard that numbers in a mathematical context or in GStudio - They of course represent a special "position" in the world space. So, vectors in GStudio can represent a position - like (0|0|0) - the famous nullvector or (23|-24.4|9) or whatever. But vectors are not only positions, they are "arrows". "Arrows?", you ask, "I thought they were positions!" - You got a point there.
Let's pretend the top of the arrow is the position, like (5|5|5). Now, imagine that position and draw a line to the nullposition (0|0|0). What you get is an arrow:



Yes, I'm sure you are amazed by my drawing skills - Look at the arrow - it does have a length, right? So, in contrary to "simple" positions, you can calculate the length of an vector, too. You can prove the following with Pythagoras, but I am too lazy to do that now
The formula for length:

length = SQUAREROOT(x²+y²+z²)

Thank you very much

Now, when you want your entity to move, like 5 quants ni the direction it looks, then your arrow should be five quants long.
Now, imagine we would "move" that array to the position of your entity and then "rotate" it, so it matches the angles of your entity, then you get what we need for "relvec".



In fact, we would only pass the vector (5|0|0) (named original vector in the picture) to c_move, everything else would be done by the engine.

Okay, so that would be relvec. Do all the stuff again, but don't rotate the arrow to fit the entities angles and you get absvec.

Move_mode? That's an easy one. The engine can ignore certain things if you want to on your movement. That way, your model might walk through models or everything which is "passable" (most like thats what you want). Have a look at the manual, everything is explained there.

Questions remaining:
1) How do we script "relvec"?
2) How shall we calculate "absvec"?
3) How to rotate the entity?
4) How to place the camera at the entities' position?
5) How can we put all of that in an action?

Answers: ;D
1) It's easy. It shall move when we hit "W" or "S". We only need to change the x-value of our vector, like this (key_w is 1 when w is pressed on the keyboard and 0 otherwise, same for key_s (of course with the s-key then )
we use temp as a temporary vector:

temp.x = 15*(key_w-key_s)*time;
temp.y = 0; //you might want to put something in here to allow strafing

Now, why time? We will put that in a loop. Faster computers might compute that more often, so we need to make the value smaller as on a computer where this line gets executed only every second or so. It will then run as fast on every computer, regardless of it's speed.

2) We will use trace for that.
c_trace(vector from,vector to, trace_mode);

Now, think of these two vectors as positions again. Now, imagine to be at position "vector from" and fire a "laser" to "vector to". Something like that would be done by trace. It returns the distance the laser could travel, so this way you can check for obstacles along the way.

ASCII-Art:

Code:

A B
in this case, trace would return the full distance from A to B, because there is no obstacle:
A-------------->B

A C B
However, in THIS case, trace would only return the length to the obstacle "C". In other words, the length of the arrow here
A------>C B



Now, how can we use this for our example? We can move the entity down, when we need it - or, in other words, when the distance to the floor (as in "the next obstacle down") is greater than, say, 40. That value depends on the scale of your level and playermodel, so play with it. Have a look at the code down there to see how we used it.

trace_mode is similar to move_mode of c_move - look at the manual, will you?

3) Rotating the entity? In our example, we have a first-person-shooter movement, so we only care for the "pan"-value. There are three rotate-values:
pan
tilt
roll.
You can write them as vectors, too! However, they aren't arrows, keep that in mind.
(pan|tilt|roll)

Anyway, which is which? Pretend a coordinate-system in your body, the one you have in WED, too (which means: Z is up) - now if you would rotate around your Z-axis, you'd change your pan-value. In other words: When you rotate, you change your pan-value

We will change it on mouse_movement in this case, which translate to this code

my.pan -= mouse_force.x*35*time; //you might want to change 35

4) That's an easy one.
vec_set(vectora,vectorb);

after this instruction, vectora is equal to vectorb, so we just need to make the position of the camera (camera.x) equal to the position of the player (player.x)

vec_set(camera.x,player.x);

You might want to add a little to camera.z, the players eyes are most likely a little higher than it's origin.

5)

Code:

ACTION simple_movement {
WHILE(1) { //do forever
temp.x = 15*(key_w-key_s)*time;
temp.y = 0; //you might want to put something in here to allow strafing
//temp.z shall be used for absolutemovement only, so we can use
//vector(x,y,z) and use only temp.x and y there in our relative movement

//calculate temp.z with trace
//we "trace" from the position of the player to the position 5000 quants under him
temp.z = 0; //without any gravity
IF(c_trace(player.x,vector(player.x,player.y,player.z-5000),ignore_me+ignore_passable) > 40) {
temp.z -= 50*time; //add gravity
}

//now move
c_move(me,vector(temp.x,temp.y,0),vector(0,0,temp.z),ignore_passable);

//change rotation
my.pan -= mouse_force.x*35*time;

//last but not least, place the camera at my position
vec_set(camera.x,my.x);

//and make it face the same direction as me
vec_set(camera.pan,my.pan);


wait(1); //give time to render, no endless loop
}
}




Please note that this was a rather fast written overview. There might be mistakes. There might be plenty of them.

Nontheless, I tried to make the issue easy to understand and easy to follow. I hope it helped you. If there are any questions ask. Any feedback appreciated


PS: That questions is asked quite often. Anyone could move it to the Frequently-asked-questions forum?


Perhaps this post will get me points for originality at least.

Check out Dungeon Deities! It's amazing and will make you happy, successful and almost certainly more attractive! It might be true!