1 registered members (henrybane),
1,499
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
A newbe question - player walk action
#392321
01/21/12 16:58
01/21/12 16:58
|
Joined: Jan 2012
Posts: 4
AdamV
OP
Guest
|
OP
Guest
Joined: Jan 2012
Posts: 4
|
Hi All, I just pretty recently learned about GameStudio and am very excited about it. I have been trying few 3D game engines before, yet none were that close to what I was looking for as A8 is. I love the Lite_C idea being C/C++ developer myself. It is great to have MED and WEB on board too. Way to go! I downloaded and installed demo of A8 and after spending last 4-5 days getting through tutorials and examples, I am pretty much confused by one thing. I am sorry if this is a silly question, yet I was unable to find the way to do it using the official tutorials or by looking into samples. I created a simple room using WED and wanted to test it the way player would do it. From docs I learned I need an action to do the player walk - there is even a sample action available in help. But I am sure I miss something since I do not know how to connect the action to whatever the player object would be. Here's what I did: 1) (WED) Created a simple box/room and gave it some textures 2) (SED) Created a sample code:
///////////////////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////////////////////////////////////////////////////////
action player_walk()
{
// if the entity has a non standard size, make sure that the bounding box does not drag along the floor
if ((my.eflags&FAT) && (my.eflags&NARROW)) // when FAT+NARROW are both set
my.min_z *= 0.5;
var speed_down = 0; // downward speed by gravity
var anim_percent = 0; // animation percentage
VECTOR vFeet;
vec_for_min(vFeet,me); // vFeet.z = distance from player origin to lowest vertex
while (1)
{
// rotate the player using the [A] and [D] keys
my.pan += 5*(key_a-key_d)*time_step;
// determine the ground distance by a downwards trace
var dist_down;
if (c_trace(my.x,vector(my.x,my.y,my.z-5000),IGNORE_ME | IGNORE_PASSABLE | USE_BOX) > 0)
dist_down = my.z + vFeet.z - target.z; // get distance between player's feet and the ground
else
dist_down = 0;
// apply gravity when the player is in the air
if (dist_down > 0) // above floor, fall down with increasing speed
dist_down = clamp(dist_down,0,accelerate(speed_down,5,0.1));
else // on or below floor, set downward speed to zero
speed_down = 0;
// move the player using the [W] and [S] keys
var dist_ahead = 5*(key_w-key_s)*time_step;
dist_ahead = sign(dist_ahead)*(abs(dist_ahead) + 0.5*dist_down); // adapt the speed on slopes
c_move(me,vector(dist_ahead,0,0),vector(0,0,-dist_down),IGNORE_PASSABLE | GLIDE); // move the player
// animate the player according to its moved distance
if (dist_ahead != 0) // player is moving ahead
{
anim_percent += 1.3*dist_ahead; // 1.3 = walk cycle percentage per quant
ent_animate(me,"walk",anim_percent,ANM_CYCLE); // play the "walk" animation
}
else // player stands still
{
anim_percent += 5*time_step;
ent_animate(me,"stand",anim_percent,ANM_CYCLE); // play the "stand" animation
}
wait(1);
}
}
function main()
{
video_mode = 8;
level_load ("test2.wmb");
wait(2); // wait until the level is loaded
}
3) Started the script from SED After that I can just fly through all of the walls and entities without any usage of the player_walk action. I am pretty sure I do something wrong or miss something. Can you please turn and shove me into the right direction I would use to learn more of the GameStudio?
|
|
|
Re: A newbe question - player walk action
[Re: AdamV]
#392324
01/21/12 17:52
01/21/12 17:52
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
You're welcome! Indeed, the script does not contain camera placement. Add the following lines of code:
At the beginning of your player action, at least before the while loop: camera.genius = me; // makes the object invisible if the camera is inside its hull
In the loop after your c_move:
vec_set(camera.x,vector(my.x,my.y,my.z+my.max_z*0.9)); // my.max_z*0.9 should be somewhere where his eyes are. you may have to change the factor or even add some quants, f.i. +16 vec_set(camera.pan,my.pan);
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|