3rd Person Cam(gauging Interest)

Posted By: laethyn

3rd Person Cam(gauging Interest) - 01/12/06 14:24

So, just wondering if anyone is still interested in having a 3rd Person Camera system.

As of now, clicking anywhere in the level rotates the player, and animates the character as he walks over to that point. Right mouse button handles rotating the camera, as well as changing the tilt. Middle mouse button handles Zooming.

Clicking on another entity (assigned with the appropriate action), will walk the player to that NPC, and open some dialog (which is not working perfectly yet, but it's getting close).

They whole system is similar in style to the NWN system. If I garner enough interest, perhaps I can be persuaded to post the scripts
Posted By: Josh666

Re: 3rd Person Cam(gauging Interest) - 01/12/06 16:27

I am super interested.
Posted By: broozar

Re: 3rd Person Cam(gauging Interest) - 01/12/06 16:56

you cannot imagine - iŽd die for it.... seriously. post it. NOW!
Posted By: laethyn

Re: 3rd Person Cam(gauging Interest) - 01/12/06 18:58

Because I'm anal that way, as soon as I get the NPC system figured out, I will post the scripts I have.

The steps I have been taking are as follows:

1. Camera & Mouse Movement
2. Interactiving with NPCs

building off that will be:

3. Merchants and purchsing from NPCs
4. Inventory
5. Equiping Items, and player stats
6. Skills
7. Spells
8. Combat
9. Journal, Map, and Compass

I should have it posted by the middle of the next week. Just dealing with some family crisis right now, which will be resolved as of Monday.

And, just so there is no confusion, it was built using a couple of different tutorial ideas, and building from there. Unfortunately, I have NO idea where the tutorials originated from, so I cannot give credit where credit is due
Posted By: laethyn

Re: 3rd Person Cam(gauging Interest) - 01/12/06 19:04

Speaking of which, anyone have any ideas what code snippet I would use to assign strings to a text function?

I can assign one, but for some reason, when I attempt to assign a second one, it ignores it and uses the first. Obviously, this is not all the code I'm using, but I think it shows the gist of what I'm trying to get at. ..

ie

string = "hi there";
string1 = "well hello";

text dialog
{
....
}

function assign1()
{
dialog.string = string;
}

function assign2()
{
dialog.string = string1;
}

Odd that it continously shows the "string" text, and assigning string1 fails to reassign dialog.string.

Ah well. I'll figure it out and get everything posted as soon as I can
Posted By: testDummy

Re: 3rd Person Cam(gauging Interest) - 01/12/06 21:59

The word "string'", which is used to define a string, is a reserved keyword in C-Script. I recommend that you do not use names which are reserved keywords in the language. I suspect that using names which are reserved keywords in the C-Script language, may result in scripting errors and/or unpredictable behavior. This is almost common sense, so I'll assume, in this case, I simply misinterpreted your example.
Posted By: Bilbo

Re: 3rd Person Cam(gauging Interest) - 01/12/06 22:16

wow that would be ace if you can get it done!
Posted By: laethyn

Re: 3rd Person Cam(gauging Interest) - 01/13/06 02:30

Here, let me qoute myself:

Obviously, this is not all the code I'm using, but I think it shows the gist of what I'm trying to get at. ..

I am NOT using the "string" keyword. It was an example. As of right now, I'm using:

string test = "ummm hello there!";

and

string test1 = "Well aren't you an idiot for taking this long to figure it out!";
Posted By: testDummy

Re: 3rd Person Cam(gauging Interest) - 01/13/06 20:05

If in string test1, you are referring to yourself, and the length of time it took to "figure it out" is determinate or known, then no doubt, you've already figured it out.
It's possible that I've misinterpreted your words. You may not have "figured it out", so with the following you should be able to pretend you had already figured it out.
Traditionally:
Code:

string test = "Greetings and salutations!";
string test1 = "Hello. I'm just your average dummy."
text dialog {
strings = 1;
string " "; // 1
}
function assign1() {
str_cpy(dialog.string[0], test);
}
function assign2() {
str_cpy(dialog.string[0], test1);
}


Posted By: laethyn

Re: 3rd Person Cam(gauging Interest) - 01/13/06 21:00

lol yes, I was refering to myself and the amount of time it took ME to figure it out. Which I have. Figured it out this morning, in fact.
Posted By: Lion_Ts

Re: 3rd Person Cam(gauging Interest) - 01/15/06 00:32

Post your work, not your words, how great it will be
If you want to talk about it, place post in other thread, not in contrib...
Posted By: laethyn

Re: 3rd Person Cam(gauging Interest) - 01/15/06 06:29

I will be posting it. Just cleaning up the code, and, as I said, dealing with some family issues. Should be online in a day or two. I don't want to post code that works, sometimes. Besides, why should I post my work if there is no interest in people wanting it?
Posted By: laethyn

Re: 3rd Person Cam(gauging Interest) - 01/17/06 01:49

As promised...

My test level included a small area, one player mdl, and two different NPC models. But you can mess around with it as you see fit. I don't claim to have pretty code, but it works! lol This is provided as is, and is working on my system. So if it doesn't work, I have NO idea why. And I won't be updating to it, adding to it, whatever. As I continue, the rest of my code will be my own. So, here is a basic starter for a 3d cam, with rotate, zoom, mouse clicking to move, and mouse clicking to talk to NPCs

Code:
//////////////////////
// Set includes

include <vars.wdl>;
include <interface.wdl>;
include <camera.wdl>;
include <movement.wdl>;

/////////////////////
// Set mouse cursor bitmap

bmap arrow = <arrow.pcx>;

/////////////////////
// Set video mode

var video_mode = 8;

/////////////////////
// Turn mouse on

function mouse_on()
{
mouse_map = arrow; // set mouse to bitmap
mouse_mode += 1;
if (mouse_mode > 1) // if it's anything but 0, set it to 0
{
mouse_mode=0;
}
while (mouse_mode > 0) // while mouse_mode is 0, have the mouse bitmap follow the pointer
{
mouse_pos.x = pointer.x;
mouse_pos.y = pointer.y;
wait(1);
}
}

function main()
{
level_load("build.wmb"); // load the level
wait(1);

init_cameras(); // initialize camera
}



Code:
//////////////////////////
// <vars.wdl>

//////////////////////////
// entities
entity* player;
entity* NPC;

//////////////////////////
// defines
define convo, skill100;

//////////////////////////
// movement variables

var vecFrom[3];
var vecTo[3];
var my_target[3];
var move_position[3];
var move_position_2[3];
var move_pos[5];
var vecFrom[3];
var vecTo[3];
var move_dist[3];
var gravity_scan_height[3];
var gravity_scan_height_result;
var start_game = 0;

///////////////////////////
// camera variables

var eye_height = 25;
var tilt_1st = 0;
var cam_turnspeed = 2;
var max_tilt_1st = 40;
var dist_planar = 250;
var cam_angle = 25;
var dist_total = 250;
var tilt_3rd = 45;
var dist_traced;

///////////////////////////
// dialog variables

var noWalk;
var tempTalk = 0;
var maxConvo;



Code:
//////////////////////////////////////
// <interface.wdl>

///////////////////////////////
// main interface image - 1024 x 768
bmap main_panel = <main_interface.bmp>;

////////////////////////////////
// Dialog panel - 792 x 122
bmap dlg_panel = <dialog_panel.bmp>;

////////////////////////////////
// Arrows to handle dialog navigation
// all images are 20x17
bmap previous_bmp = <prev_bmp.bmp>;
bmap next_bmp = <next_bmp.bmp>;
bmap prev_over_bmp = <prev_ovr_bmp.bmp>;
bmap next_over_bmp = <nxt_ovr_bmp.bmp>;

/////////////////////////////////////////
// font used - change to whatever you wish
FONT dialog_fnt = <dialog_font.bmp>, 21, 17;

/////////////////////////////////////////
// Some simple test strings
string test = "want 50 gold?";
string test1 = "This is number 1";
string test2 = "This is number 2";
string test3 = "this is number 3";
string woman1 = "I'm a woman";
string woman2 = "see my boobs?";

/////////////////////////////////////////
// Create main interface panel
panel main_interface
{
bmap = main_panel;
layer = 7;
pos_x = 0;
pos_y = 0;
flags = refresh, visible, overlay;
}

/////////////////////////////////////////
// dialog panel
panel dialog
{
bmap = dlg_panel;
layer = 8;
pos_x = 100;
pos_y = 646;
BUTTON = 675, 103, next_bmp, next_bmp, next_over_bmp, next_text, off_scroll, over_scroll;
BUTTON = 65, 103, previous_bmp, previous_bmp, prev_over_bmp, scrll_txt_down, off_scroll, over_scroll;
flags = refresh, d3d, overlay;
}

/////////////////////////////////////////
// text for NPC dialog
text display_dlg_panel
{
pos_x = 120;
pos_y = 690;
font = dialog_fnt;
layer = 6;
flags = d3d, narrow;
}

function display_dlg()
{
dialog.visible = on; // Turn dialog panel on
display_dlg_panel.visible = on; // Turn text on
}

function talk_to_NPC()
{
display_dlg(); // Display the dialog
tempTalk = 1; // sets temptalk - temptalk handles stopping the players animation when near the NPC
}

function NPC_Coll()
{
// Was the NPC clicked?
if(event_type == event_click)
{
// if the distance between the NPC and the player is greater than 50
while(c_trace(me.x, player.x, IGNORE_ME) > 50)
{
// don't do anything yet. Distance is still to great
wait(1);
}
NPC = me; // Sets NPC entity - seems redundant, but won't work without
me.pan = player.pan - 180; // Rotate the NPC to look at the player
talk_to_NPC(); // Run the function
}
}

function clicked_NPC()
{
// enable the click event, and run the player/NPC collision
me.enable_click = on;
me.event = NPC_Coll;
}

///////////////////////////////////////////////////
// Create actions for NPCs
// *** TODO: Create system to allow for random strings to be shown

action click_me_Woman
{
NPC = me; // Set the NPC entity
while(1)
{
// player to NPC distance greater than 50?
if(c_trace(me.x, player.x, IGNORE_ME) > 50)
{
// Don't do anything yet. Distance is to great
wait(1);
}
else
{
// Set maximum number of conversations This should be number of strings to display + 1
maxConvo = 3;

// If the NPC skill is 1, set the first string
if(me.convo == 1)
{
display_dlg_panel.string = woman1;
}
// if 2, second string (others are the same, I shouldn't need to go into detail)
if(me.convo == 2)
{
display_dlg_panel.string = woman2;
}
// If the skill is the max, or 0, just wait
if(me.convo == 3 || me.convo == 0)
{
wait(1);
}

// Begin dialog display system
clicked_NPC();
}
wait(1);
}
}

action click_me_Warlock // Same actions as woman, just move conversation
{
NPC = me;
while(1)
{
if(c_trace(me.x, player.x, IGNORE_ME) > 50)
{
wait(1);
}
else
{
maxConvo = 5;
if(me.convo == 1)
{
display_dlg_panel.string = test;
}
if(me.convo == 2)
{
display_dlg_panel.string = test1;
}
if(me.convo == 3)
{
display_dlg_panel.string = test2;
}
if(me.convo == 4)
{
display_dlg_panel.string = test3;
}
if(me.convo == 5 || me.convo == 0)
{
wait(1);
}
clicked_NPC();
}
wait(1);
}
}

function hide_dialog()
{
// make player able to animate again
tempTalk = 0;
// turn off dialog and dialog panel
display_dlg_panel.visible = off;
dialog.visible = off;
// reset NPC convo skill
NPC.convo = 1;
}

////////////////////////////////////
// The following two functions set a flag to prevent walking when clicking on the
// next and previous buttons in the panel - if not set, when the player clicks the next
// button, the dialog dissappears, and the player walks to where the mouse was
function over_scroll()
{
while(1)
{
noWalk = 1;
wait(1);
}

}

function off_scroll()
{
while(1)
{
noWalk = 0;
wait(1);
}
}

//////////////////////////////////
// The following two functions handle moving forward and back through
// the NPC dialog

function next_text()
{
NPC.convo += 1;
if(NPC.convo == maxConvo)
{
NPC.convo = maxConvo - 1;
}
}

function scrll_txt_down()
{
NPC.convo -= 1;
if(NPC.convo == 0)
{
NPC.convo = 1;
}
}



Code:
/////////////////////////////////////////
// <camera.wdl>

////////////////////////////////////
// define 3rd person camera view

view 3rd_person
{
layer = 1;
pos_x = 0;
pos_y = 0;
}

function update_views()
{
dist_planar = cos(tilt_3rd) * dist_total;
3rd_person.x = player.x - cos(cam_angle) * dist_planar;
3rd_person.y = player.y - sin(cam_angle) * dist_planar;
3rd_person.z = player.z + sin(tilt_3rd) * dist_total;
3rd_person.pan = cam_angle;
3rd_person.roll = 0;
3rd_person.tilt = -tilt_3rd;
validate_view();
}

/////////////////////////////////////
// Camera collision
// **** Needs Improvement ****

function validate_view()
{
my = player;
trace_mode = ignore_me + ignore_passable;
dist_traced = trace(player.x, 3rd_person.x);
if(dist_traced == 0)
{
return;
}
if(dist_traced < dist_total)
{
dist_traced -= 6; // 5? 6? Run some tests
dist_planar = cos(tilt_3rd) * dist_traced;
3rd_person.x = player.x - cos(cam_angle) * dist_planar;
3rd_person.y = player.y - sin(cam_angle) * dist_planar;
3rd_person.z = player.z + sin(tilt_3rd) * dist_traced;
}
}

function orbit_camera()
{
while(mouse_right == 1) // while holding down the right mouse button
{
// set the camera angle to the mouse force
cam_angle += mouse_force.x/50; // lower/raise the "50" to speed up/slow down the camera
if(cam_angle > 360)
{
cam_angle = cam_angle - 360;
}
if(cam_angle < 0)
{
cam_angle = cam_angle + 360;
}
wait(1);
}
}

function tilt_cam()
{
while(mouse_right == 1) // while holding down the right mouse button
{
// set the tilt of the camera to the mouse movement
tilt_3rd += mouse_force.y/50; // lower/raise the "50" to change the speed of the camera movement

// limit the lowest camera tilt to -6
// change both -6 to whatever to limit the tilt
if(tilt_3rd < -6)
{
tilt_3rd = -6;
}
// set the upper limit of the tilt
// 90 is looking straight down
// change both "65" to change the camera tilt limit
if(tilt_3rd > 65)
{
tilt_3rd = 65;
}
wait(1);
}
}

function zoom_camera()
{
while(mouse_middle == 1) // while holding down the middle mouse button
{
// change the camera arc based on the mouse movement
3rd_person.arc -= mouse_force.y/10; // lower the "10" to speed up or slow down cam movement

// clamp the cameras arc to the limit
3rd_person.arc = clamp(3rd_person.arc, 25, 65);
wait(1);
}
}

function init_cameras()
{
camera.visible = off; // disable default camera

// set the camera size to the screen size
3rd_person.size_x = screen_size.x;
3rd_person.size_y = screen_size.y;

// turn on the 3rd person camera
3rd_person.visible = on;
}



Code:
//////////////////////////////////
// <movement.wdl>

action get_target
{
// This is to prevent the player from walking when the game starts up
// Couldn't get it to stop for some reason
if(start_game == 0)
{
start_game = 1;
}

// Stop walking while mouse is over next/previous buttons
while(noWalk == 1)
{
wait(1);
}

mouse_to_level();
vec_set(my_target,target);
vec_set(move_position,target);
vec_set(move_position_2,move_position);
vec_sub(move_position_2,player.x);

hide_dialog();
}

// convert the mouse click to coordinates where to move player
function mouse_to_level()
{
vecFrom.x = mouse_pos.x;
vecFrom.y = mouse_pos.y;
vecFrom.z = 5;
vec_set(vecTo,vecFrom);
vec_for_screen(vecFrom,3rd_person);
vecTo.z = 5000;
vec_for_screen(vecTo,3rd_person);
return(trace(vecFrom,vecTo));
}

////////////////////////////////////////////////////
// Assign this action to the player!!!
// ***Gravity is screwed up, player is standing a quant above the ground it seems***

action move_player
{
player = me;
mouse_on();
while(1)
{
vec_set(gravity_scan_height,my.x);
gravity_scan_height.z -= 4000;
trace_mode = ignore_me + ignore_sprites + ignore_models + use_box;
gravity_scan_height_result = trace(my.x,gravity_scan_height);
if(gravity_scan_height_result > 3)
{
move_dist.z = -5 * time;
}
else
{
if(gravity_scan_height_result > 1)
{
move_dist.z = 0;
}
else
{
move_dist.z = 5*time;
}
}
move_pos[1] = move_position.x - 5;
move_pos[2] = move_position.x + 5;
move_pos[3] = move_position.y - 5;
move_pos[4] = move_position.y + 5;
if(move_pos[1] < player.x && move_pos[2] > player.x && move_pos[3] < player.y && move_pos[4] > player.y || start_game == 0)
{
move_dist.x = 0;
ent_cycle("stand", my.skill20);
my.skill20 += 2 * time;
my.skill20 %= 100;
}
else
{
vec_to_angle(player.pan,move_position_2);
player.tilt = 0;
move_dist.x = 15*time;
ent_cycle("walk", my.skill20);
my.skill20 += 4 * time;
my.skill20 %= 100;
if(tempTalk == 1)
{
if(c_trace(me.x, NPC.x, IGNORE_ME) < 45)
{
move_dist.x = 0;
ent_cycle("stand", my.skill20);
my.skill20 += 2 * time;
my.skill20 %= 100;
wait(1);
}
}
}
move_mode = ignore_passable;
ent_move(move_dist.x,nullvector);
wait(1);

// fun camera functions
orbit_camera();
zoom_camera();
tilt_cam();
update_views();
}
}

// run function when mouse is clicked
on_mouse_left = get_target;




But, whatever, lemme know what you think

Cheers!
Posted By: Lion_Ts

Re: 3rd Person Cam(gauging Interest) - 01/17/06 03:50

thank you, laethyn!
have to try what is this...
Posted By: laethyn

Re: 3rd Person Cam(gauging Interest) - 01/17/06 04:24

by the way, each code snippet here is a different wdl. As named in the comment section at the top of each code area.
Posted By: Kotakide

Re: 3rd Person Cam(gauging Interest) - 02/14/06 06:09

it doesn't work !!
I dont understand how to implement this?
give me an enlightenmnet..
I'm a newbie
© 2024 lite-C Forums