Questions from the forum |
Top Previous Next |
Q: How can I make entity's tilt & roll angles adjust according to the terrain normal? I know that this can be done, because it is implemented in the Car Demo project. A: Here's the car demo code that does what you need:
ANGLE temp_angles; // make this a local ANGLE if you use several identical entities
// set proper tilt and roll angles for the AI cars depending on the slopes they're on c_trace(my.x, temp.x, IGNORE_ME | IGNORE_PASSABLE); temp_angles.tilt = 0; temp_angles.roll = 0; temp_angles.pan = -my.pan; vec_rotate(normal, temp_angles); temp_angles.tilt = -asin(normal.x); temp_angles.roll = -asin(normal.y); my.tilt += 0.1 * ang(temp_angles.tilt - my.tilt); // play with 0.1 - it sets the angle adjusting speed my.roll += 0.1 * ang(temp_angles.roll - my.roll); // play with 0.1 - it sets the angle adjusting speed
Q: Can I see a simple level_loadendless example that makes the camera hover above the unlimited, terrain-based level? A: Take a look at the code below; it's as simple as it can be; level_loadendless creates 8 additional views that surround the existing level, thus making it repeat endlessly. Don't forget to include level.c in your projects; otherwise, the code won't work.
#include <acknex.h> #include <default.c> #include <level.c>
function main() { level_loadendless("terrain.hmp"); terrain_tile(level_ent); ent_createlayer("skycube+6.tga",SKY | CUBE | SHOW, 0); wait (3); def_move(); // default movement from default.c camera.z = 500; // experimental value, play with it camera.tilt = -15; // look downwards a bit camera.clip_far = 1000; // set this value to about 200% of your terrain size in quants while (1) // move the camera position endlessly { camera.x += 10 * time_step; // camera movement speed, play with it wait (1); } }
Q: I wish to read the content of a file into a string, including all the carriage returns (\r) and line feeds (\n) characters. My problem is that the functions that come with Gamestudio appear to cut out carriage returns and line feeds no matter what I do. A: Don't use file_str_read, but file_str_readto, which allows you to set your own delimiter. Here's a simple example:
STRING* huge_str = "#10000"; // this string can hold up to 10,000 characters
TEXT* huge_txt = { pos_x = 10; pos_y = 15; layer = 20; string(huge_str); flags = SHOW; }
function read_startup() { var filehandle; filehandle = file_open_read("my.txt"); // read the text from this file and copy it to huge_str file_str_readto(filehandle, huge_str, "!", 10000); // use ! as a separator (ignore \r, \n, etc) and read up to 10000 characters file_close (filehandle); // now close the file }
Q: Should I make my sprites bigger, and then scale them down to produce better looking graphics? A: If you are building a 2D game, you should always set the scale of your sprites to 1. For 3D games, it may be a good idea to use high resolution, scaled down sprites; you will see the visual difference between a standard sprite and its 4 times higher resolution, scaled down version below. It is true that larger sprites use more memory, but these days any decent video card has plenty of it.
function scale_sprite() { my.scale_x = 0.25; my.scale_y = my.scale_x; }
function sprites_startup() { wait (-3); ent_create ("bg.jpg", vector(0, 0, 100), NULL); ent_create ("bg2.jpg", vector(300, 0, 100), scale_sprite); }
Q: How can you check if a specific save file exists before loading? A: There you go:
function load_game() { var filehandle; filehandle = file_open_read("mysave.dat"); // open the file if (filehandle) // the file exists? { // then do your thing here } }
Q: Does anyone know where to get the Aum 1 to 100 collection? A: The collection was a part of the user-donated Aum 100 anniversary contributions and can be found here:
http://aum.conitec.net/aum100contributions3.zip
Nevertheless, I have uploaded an updated version of it and I will continue to do that from time to time. The url (and thus the file name) will remain the same:
http://aum.conitec.net/aum1-100.chm
Don't forget to right click the downloaded chm file, and then choose "Unlock" if you can't see its content.
Q: I'd need code for a player that moves along the Y axis and at a certain Y value to trigger an ambient sound file. A: There you go:
action sideway_player() // simple sideway player and camera code { var walk_percentage; var stand_percentage; var trigger_once = 0; player = my; // I'm the player my.pan = 270; // set player's orientation while (1) { // move the player using the left / right cursor keys; 10 sets the movement speed c_move (my, vector(10 * (key_cul - key_cur) * time_step, 0, 0), nullvector, GLIDE); // place the camera 0 quants in front of the player, 200 quants sideways and 25 quants above player's origin vec_set (camera.x, vector(0, 200, 25)); vec_rotate (camera.x, player.pan); vec_add (camera.x, player.x); camera.pan = player.pan - 90; // make the camera look at the player from a sideview perspective if (key_cur + key_cul) // the player is moving? { walk_percentage += 5 * time_step; ent_animate(my, "walk", walk_percentage, ANM_CYCLE); stand_percentage = 0; } else // the player is standing still (or rotating) { stand_percentage += 1.5 * time_step; ent_animate(my, "stand", stand_percentage, ANM_CYCLE); walk_percentage = 0; } if ((player.y < -500) && (trigger_once == 0)) // the player has reached the sound triggering point? { trigger_once = 1; // don't trigger the event more than once beep(); // simple sound effect, do what you need here } wait (1); } }
Q: I'm working with the Shooter Template from AUM. Does anyone know how to get the elevator to move downwards? A: Open t_elevators.c, and then find these lines of code:
if (my.z < my.elevator_height) // the elevator didn't reach its destination yet? { .... }
Set negative Elevator_height values in Wed, and then replace "<" with ">". Here's how the modified code should look like:
if (my.z > my.elevator_height) // the elevator didn't reach its destination yet? { .... }
Don't forget to set negative "Elevator_speed" values as well.
Q: I want to ask if there is any possibility to get the number of frames of an animation scene? A: Here's a snippet derived from one of Superku's brilliant ideas.
var frame1, frame2, number_of_frames;
action model_frames() { ent_animate(my, "walk", 0, NULL); // play the first animation frame frame1 = my.frame; ent_animate(my, "walk", 100, NULL); // play the last animation frame frame2 = my.frame; number_of_frames = frame2 - frame1 + 1; }
PANEL* frames_pan = { layer = 15; digits(10, 10, "Number of frames: %.f", *, 1, number_of_frames); flags = SHOW; }
Q: Does anyone know how to display a variable over a model? What I mean is that when the player walks up to a model, he can see a number that can change its value on top of it. A: There you go:
var health = 90;
PANEL* health_pan = { digits(0, 0, 3, *, 1, health); flags = SHOW; }
action my_model() { var anim_percentage; my.skill40 = health; VECTOR temp_pos; while (1) { c_move (my, vector(3 * time_step, 0, 0), nullvector, GLIDE); // "5" controls the walking speed my.pan += 2 * time_step; // walk in a circle ent_animate(my, "walk", anim_percentage, ANM_CYCLE); anim_percentage += 4 * time_step; // "6" controls the "walk" animation speed
vec_set (temp_pos, my.x); // copy the xyz coordinates of the entity to temp_pos temp_pos.z += 60; // play with this value vec_to_screen (temp_pos, camera); // convert the 3D position to 2D screen coordinates health_pan.pos_x = temp_pos.x; // and then set the position of the text health_pan.pos_y = temp_pos.y; // on x and y
wait (1); } }
|