Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
2 registered members (3run, AndrewAMD), 623 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
CAMERA code #169716
11/27/07 16:45
11/27/07 16:45
Joined: Nov 2007
Posts: 1,032
Croatia
croman Offline OP
Serious User
croman  Offline OP
Serious User

Joined: Nov 2007
Posts: 1,032
Croatia
OK people...I'm having a problem. I'm killing myself trying to make it work. The biggest problem is that my.pan knows to "break"...on for example 249 it jumps suddenly to some other number. In manual is written that my.pan is going from 0...360 but it goes even more...without end. I really need your help. Code isn't wrong, I give my right hand in fire for that... HELP!!! here's the code::::::::

function camera_update()
{
if(paner>360){paner -= 360;}if(paner<0){paner += 360;}
if(my.pan>360){my.pan -= 360;}if(my.pan<0){my.pan += 360;}
if(!key_i && !key_j && !key_l && !key_k){
if(paner < my.pan){
paner += 1;
paner = min(paner,my.pan);
}
if(paner > my.pan){
paner -= 1;
paner = max(paner,my.pan);
}
}

camera.x = my.x - 250 * cos(paner) * cam_dist;
camera.y = my.y - 250 * sin(paner) * cam_dist;

if(skok == 0)
{
if(camera.z < my.z +125){
if(camera.z == my.z +125){
camera.z =my.z +125;
}
camera.z += 15*time;
}
if(camera.z > my.z +125){
if(camera.z == my.z +125){
camera.z =my.z +125;
}
camera.z -= 15*time;
}
}
vec_set(rot_cam, my.x);
vec_sub(rot_cam, camera.x);
vec_to_angle(camera.pan, rot_cam);
}



Ubi bene, ibi Patria.
Re: CAMERA code [Re: croman] #169717
11/27/07 16:56
11/27/07 16:56
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
if you define ANGLE* myang, I believe values will go from 0 to 360. Pan however is declared as a VECTOR in the entity structure. And Vectors contain normal numbers. If you use ang(), you can limit the variable between -180 and 180. So ang (my.pan) + 180 gives a result between 0 and 360.

Now give me your hand and a fire >:D

Last edited by Joozey; 11/27/07 16:57.

Click and join the 3dgs irc community!
Room: #3dgs
Re: CAMERA code [Re: Joozey] #169718
11/27/07 17:04
11/27/07 17:04
Joined: Nov 2007
Posts: 1,032
Croatia
croman Offline OP
Serious User
croman  Offline OP
Serious User

Joined: Nov 2007
Posts: 1,032
Croatia
ok

Last edited by cerberi; 11/27/07 17:05.


Ubi bene, ibi Patria.
Re: CAMERA code [Re: croman] #169719
11/27/07 17:05
11/27/07 17:05
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Oh... right, well at least you know why its not limited by 0 and 360. And ang() will work nonetheless.

EDIT: gah you editted

Last edited by Joozey; 11/27/07 17:06.

Click and join the 3dgs irc community!
Room: #3dgs
Re: CAMERA code [Re: Joozey] #169720
11/27/07 17:12
11/27/07 17:12
Joined: Nov 2007
Posts: 1,032
Croatia
croman Offline OP
Serious User
croman  Offline OP
Serious User

Joined: Nov 2007
Posts: 1,032
Croatia
I can't believe it!!! It's not good. Sorry. Can anyone help??? Or write me down solution for that piece of code.

Last edited by cerberi; 11/27/07 17:32.


Ubi bene, ibi Patria.
Re: CAMERA code [Re: croman] #169721
11/27/07 17:57
11/27/07 17:57
Joined: Sep 2006
Posts: 292
M
Mythran Offline
Member
Mythran  Offline
Member
M

Joined: Sep 2006
Posts: 292
If (paner => 360) {paner == 0;}
If (paner <= 0){paner == 360;}

You want it to go from 0 to 360 and the otherwise, or you want it to jump directly from 0 to 360 or 360 to 0?

Re: CAMERA code [Re: Mythran] #169722
11/27/07 18:02
11/27/07 18:02
Joined: Nov 2007
Posts: 1,032
Croatia
croman Offline OP
Serious User
croman  Offline OP
Serious User

Joined: Nov 2007
Posts: 1,032
Croatia
nope...not good



Ubi bene, ibi Patria.
Re: CAMERA code [Re: croman] #169723
11/27/07 18:54
11/27/07 18:54
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
you specified the problem as the variable exceeds 360, so we thought of a solution for you. If it's not good, then specify your problem better to us. How can we know what your problem is?

Can you see whats wrong with the following piece of code?
Code:

function main() {
player.x += 5;
}



No? And if I tell you that my player doesn't move? Do you know the problem now?
That's what we need from you, the problem itself, not just the possible cause for the problem and the code. And I can assure you that ang() and Mythran's solution are both the right ones for solving the exceeding 360 issue.

Last edited by Joozey; 11/27/07 18:58.

Click and join the 3dgs irc community!
Room: #3dgs
Re: CAMERA code [Re: Joozey] #169724
11/27/07 20:06
11/27/07 20:06
Joined: Nov 2007
Posts: 1,032
Croatia
croman Offline OP
Serious User
croman  Offline OP
Serious User

Joined: Nov 2007
Posts: 1,032
Croatia
well...put that code in first post like this::::

action player()
{
player = me;
while(1)
{
handle_movement();
handle_camera(1);
wait(1);
}

function player_move()
{
temp.x = -1000;
temp.y = 0;

if (key_cuu == 1 && key_cud == 0 && key_cul == 0 && key_cur == 0) { temp.x = camera.pan; }
if (key_cud == 1 && key_cuu == 0 && key_cul == 0 && key_cur == 0) { temp.x = camera.pan + 180; }
if (key_cul == 1 && key_cud == 0 && key_cuu == 0 && key_cur == 0) { temp.x = camera.pan + 90; }
if (key_cur == 1 && key_cud == 0 && key_cul == 0 && key_cuu == 0) { temp.x = camera.pan - 90; }
if (key_cuu == 1 && key_cul == 1 && key_cur == 0 && key_cud == 0) { temp.x = camera.pan + 45; }
if (key_cuu == 1 && key_cur == 1 && key_cul == 0 && key_cud == 0) { temp.x = camera.pan - 45; }
if (key_cud == 1 && key_cul == 1 && key_cur == 0 && key_cuu == 0) { temp.x = camera.pan + 135; }
if (key_cud == 1 && key_cur == 1 && key_cul == 0 && key_cuu == 0) { temp.x = camera.pan - 135; }

if (key_i == 1 && key_k == 0 && key_j == 0 && key_l == 0){temp.x=camera.pan;}
if (key_k == 1 && key_i == 0 && key_j == 0 && key_l == 0){temp.x=camera.pan+180;}
if (key_j == 1 && key_k == 0 && key_i == 0 && key_l == 0){temp.x=camera.pan+90;paner+=1;}
if (key_l == 1 && key_k == 0 && key_j == 0 && key_i == 0){temp.x=camera.pan-90;paner-=1;}
if (key_i == 1 && key_j == 1 && key_l == 0 && key_k == 0){temp.x=camera.pan+45;paner+=1;}
if (key_i == 1 && key_l == 1 && key_j == 0 && key_k == 0){temp.x=camera.pan-45;paner-=1;}
if (key_k == 1 && key_j == 1 && key_l == 0 && key_i == 0){temp.x=camera.pan+135;paner+=1;}
if (key_k == 1 && key_l == 1 && key_j == 0 && key_i == 0){temp.x=camera.pan-135;paner-=1;}

if (temp.x != -1000){if (key_shift == 1) { temp.y = 10 * time; } else { temp.y = 15 * time; }}
my.move_x = fcos(temp.x,temp.y);
my.move_y = fsin(temp.x,temp.y);
c_move(my,nullvector,my.move_x,use_aabb | ignore_passable | glide);

if (my.move_x != 0 || my.move_y != 0) { //if we are moving
if (my.animblend == stand) { //if our current animation is stand
if (key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; }
}
if (my.animblend == run && key_shift == 1) { my.blendframe = walk; }
if (my.animblend == walk && key_shift == 0) { my.blendframe = run; }
}
else {
if (my.animblend > stand && my.animblend != jump && my.animblend != fall)
{
//if we aren't moving and our current animation is walk or run, blend and cycle the stand
//animation
my.blendframe = stand;
}
}
result = trace(vector(my.x,my.y,my.z - my.z_offset),vector(my.x,my.y,my.z - 4000));
if (result < 0) { my.z -= result; my.velocity_z = 0; }

if (temp.y > 0) { rotate_entity(temp.x,30); }
}

function rotate_entity(rotate_angle,rotate_speed)
{
if (my.pan == rotate_angle) { return; }
result = ang(rotate_angle - my.pan);
if (result > 0) { my.pan += rotate_speed * time; }
if (result < 0) { my.pan -= rotate_speed * time; }
if (ang(rotate_angle - my.pan) < 0 && result > 0) { my.pan = rotate_angle; }
if (ang(rotate_angle - my.pan) > 0 && result < 0) { my.pan = rotate_angle; }
}

function handle_gravity()
{
trace_mode = ignore_me+ignore_passable+use_box;
result = trace(vector(my.x,my.y,my.z - my.z_offset),vector(my.x,my.y,my.z - 4000));
if (result < 3) {
if (my.jumping_mode == 0) {
skok=0;
skokoliko = 0;
my.force_z = -1 * result;
if (key_e == 0 && space_press == 1) { space_press = 0; }
if (key_e == 1 && space_press == 0 && my.animblend >= stand && my.animblend != jump &&
my.animblend != fall && skokoliko ==0) {
space_press = 1;
skok = 1;
skokoliko = 1;
my.jumping_mode = 1;
my.force_z = 25;
my.blendframe = jump;
my.animate2 = 0;
my.animblend = blend;
}
}
if (my.jumping_mode == 2 || my.jumping_mode == 3) { my.jumping_mode = 0; }
} else {
if (key_e == 0 && space_press == 1) { space_press = 0; }
if (key_e == 1 && space_press == 0 && skokoliko == 1 && my.animblend == jump||my.animblend
== fall &&my.jumping_mode != 0 && skokoliko == 1)
{
space_press = 1;
skok = 1;
skokoliko = 1;
my.jumping_mode = 1;
my.force_z = 25;
my.blendframe = jump;
my.animate2 = 0;
my.animblend = blend;
}

if (my.jumping_mode == 2 || my.jumping_mode == 3) { my.jumping_mode = 0; }

if (my.jumping_mode == 2) {
if (result > 120) {
my.animate = 60;
my.jumping_mode = 3;
} else {
my.jumping_mode = 0;
//skok = 0;
}
}
if (my.jumping_mode == 3 && result <= 120) { skok = 0;skokoliko = 0;my.jumping_mode = 0; }
if (my.jumping_mode == 0) {
if (result > 120 && my.animblend >=stand&&my.animblend != jump&&my.animblend != fall)
{
my.jumping_mode = 3;
my.blendframe = fall;
my.animate2 = 0;
my.animblend = blend;
}
}
my.force_z -= 6 * time;
my.force_z = max(-30,my.force_z);
}
my.velocity_z += (time * my.force_z) - (min(time*0.7,1) * my.velocity_z);
my.move_z = my.velocity_z * time;
}

and here comes the handle_camera function from the first post...


ANIMATIOn


function handle_animation(animation_speed) {
if (animation_speed <= 0) { animation_speed = 1; }
if (my.animblend != blend && my.blendframe != nullframe) { my.animate2 = 0;
my.animblend = blend; }
if (my.animblend == blend) {
if (my.currentframe == stand) { ent_animate(my,"stand",my.animate,anm_cycle); }
if (my.currentframe == run) { ent_animate(my,"run",my.animate,anm_cycle); }
if (my.currentframe == walk) { ent_animate(my,"walk",my.animate,anm_cycle); }
if (my.currentframe == jump) { ent_animate(my,"jump",my.animate,0); }
if (my.currentframe == leti_normalno) { ent_animate(my,"leti_normalno",my.animate,0); }
if (my.blendframe == stand) { ent_blend("stand",0,my.animate2); }
if (my.blendframe == run) { ent_blend("run",0,my.animate2); }
if (my.blendframe == walk) { ent_blend("walk",0,my.animate2); }
if (my.blendframe == jump) { ent_blend("jump",0,my.animate2); }
if (my.blendframe == fall) { ent_blend("jump",60,my.animate2); }
if (my.blendframe == leti_normalno) { ent_blend("leti_normalno",0,my.animate2); }
my.animate2 += 45 * time;
if (my.animate2 >= 100) {
my.animate = 0;
my.animblend = my.blendframe;
my.blendframe = nullframe;
}
}
if (my.animblend == stand)
{
ent_animate(my,"stand",my.animate,anm_cycle);
my.animate += 5 * animation_speed * time;
my.animate %= 100;
my.currentframe = stand;

if(broj_stope != 3)
{
ent_create("stopalo3.bmp",my.x,stopalo);
broj_stope = 3;
}
}
if (my.animblend == run)
{
ent_animate(my,"run",my.animate,anm_cycle);
my.animate += 10 * animation_speed * time;
my.animate %= 100;
my.currentframe = run;
if(my.animate > 0)&&(my.animate < 25)
{
if(broj_stope != 2)
{
ent_create("stopalo.bmp",my.x,stopalo);
broj_stope = 2;
}
}
if(my.animate > 50)&&(my.animate < 75)
{
if(broj_stope == 2)
{
ent_create("stopalo2.bmp",my.x,stopalo);
broj_stope = 1;
}
}

}
if (my.animblend == walk) {
ent_animate(my,"walk",my.animate,anm_cycle);
my.animate += 8 * animation_speed * time;
my.animate %= 100;
my.currentframe = walk;
}
if (my.animblend == jump || my.animblend == fall) {
if (my.jumping_mode == 3) { my.animate = 60; }
ent_animate(my,"jump",my.animate,0);
broj_stope = 4;
my.animate += 13 * animation_speed * time;
my.currentframe = jump;
if (my.animate >= 60 && my.jumping_mode == 1) { my.jumping_mode = 2; }
if (my.animate >= 100) {
ent_animate(my,"jump",100,0);
my.animate = 100;
my.blendframe = stand;
if (my.move_x != 0 || my.move_y != 0) {
if (key_shift == 1) { my.blendframe = walk; } else { my.blendframe =run; }
}
}
}
}



Ubi bene, ibi Patria.
Re: CAMERA code [Re: croman] #169725
11/30/07 16:32
11/30/07 16:32
Joined: Jan 2006
Posts: 968
EpsiloN Offline
User
EpsiloN  Offline
User

Joined: Jan 2006
Posts: 968
I think the problem is somewhere where you set paner to some values. (If key_i...key_k)
And btw , for limiting a var between 0 and a certain number , put at the end of a function (or a while(1) loop)
Code:

var %= number;


This will limit var between 0 and 'number'...I think thats the best solution.


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1