Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 20:05
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Ayumi, kzhao), 1,354 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
using c_rotate... #182868
02/09/08 09:29
02/09/08 09:29
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
Hello

I'd like to use "c_rotate..." instead of "pan + = ..." in the following snippet (from the kh-movement code).
Would be great if someone could help me with this

Code:

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_step;
}
if(result < 0){
my.pan -= rotate_speed * time_step;

}
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;
}
}



Re: using c_rotate... [Re: Loopix] #182869
02/10/08 13:02
02/10/08 13:02
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline
Expert
Germanunkol  Offline
Expert

Joined: Jun 2006
Posts: 2,640
Earth
Code:

function rotate_entity(rotate_angle,rotate_speed) {
if (my.pan == rotate_angle) { return; }
result = ang(rotate_angle - my.pan);
if (result > 0){
c_rotate(my,vector(rotate_speed * time_step,0,0),ignore_passable);
}
if(result < 0){
c_rotate(my,vector(-rotate_speed * time_step,0,0),ignore_passable);

}
if (ang(rotate_angle - my.pan) < 0 && result > 0){
c_rotate(my,vector(rotate_angle - my.pan,0,0),ignore_passable);
}
if (ang(rotate_angle - my.pan) > 0 && result < 0){
c_rotate(my,vector(rotate_angle - my.pan,0,0),ignore_passable);
}
}



dunno if this works... instead of just ignore_passable, you might also need to add use_axis... I never get that right...

Micha


~"I never let school interfere with my education"~
-Mark Twain
Re: using c_rotate... [Re: Loopix] #182870
02/10/08 13:10
02/10/08 13:10
Joined: Feb 2008
Posts: 337
V
Vadim647 Offline
Senior Member
Vadim647  Offline
Senior Member
V

Joined: Feb 2008
Posts: 337
Hello Loopix! Remember me?
I know, how it's mad function > in help file they haven't written that fact, that c_rotate adds angle, not sets it.
Here is example script:
Code:

action ent1111 =
{my.shadow = on;
while(1)
{c_rotate(me,vector(1,0,0),IGNORE_PASSABLE);wait(1);}}
function main()
{video_window(nullvector,nullvector,1,"c_rotate test");video_switch(8,0,1);
fps_max = 64;detail_size = 64;vec_set(sky_color,vector(192,160,128));
level_load("map_water.hmp");wait(3);ent_create("hover.mdl",vector(-256,0,128),ent1111);}


That rotates ent's pan 1degree per sec. so, you need just to replace
Code:
my.pan+=rotate_speed * time_step;


by
Code:
c_rotate(my,vector(rotate_speed * time_step,0,0),IGNORE_PASSABLE);


also replace result by some var, for example
Code:
var temp_integer;


to avoid conflicts with c_rotate.

I just noticed that Germanunkol has sended reply while i was typing.
But hes said right, except result because its modified by c_rotate and Code:
my.pan = rotate_angle;

because back rotation can cause lag, and isn't needed because first c_rotate already checked its way.

Last edited by Vadim647; 02/10/08 13:15.

I switched to other account since marth 2010. Guess which.
Re: using c_rotate... [Re: Vadim647] #182871
02/10/08 14:54
02/10/08 14:54
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
Hey...thanks guys! I got it working now Vadim647 is a really helpfull new member of the community...he's so young and so clever

Re: using c_rotate... [Re: Loopix] #182872
02/10/08 15:27
02/10/08 15:27
Joined: Apr 2006
Posts: 1,551
Netherlands
D3D Offline
Serious User
D3D  Offline
Serious User

Joined: Apr 2006
Posts: 1,551
Netherlands
A thank you from me also. Just few questions to Loopix:

Have you replaced trace with c_trace and also did something to the collision? ATM i'm using the default USE_AABB from KH Movment tutorial, because if i'd use something else I get strange results. If I keep using USE_AABB all is fine as long if you dont step onto another model, then it push the player upwards.

Below is the half finished movement script from kh movement tutorial. Loopix ff you have some spare time can you look at your c_trace and c_move and tell me if they use USE_AABB, or maybe explain me how you fixed the collission problem with mdls and such?

Code:
#include <acknex.h>

#define nullframe -2
#define blend -1
#define stand 0
#define run 1
#define walk 2
#define jump 3
#define fall 4

#define move_x skill22 // movement skills
#define move_y skill23
#define move_z skill24
#define force_x skill25
#define force_y skill26
#define force_z skill27
#define velocity_x skill28
#define velocity_y skill29
#define velocity_z skill30

#define animate skill31
#define animate2 skill32
#define animblend skill33
#define currentframe skill34
#define blendframe skill35

#define z_offset skill50
#define jumping_mode skill51
#define gravity skill52
#define movement_mode skill53
#define moving skill54
#define hit_by_player skill55
#define entity_type skill56

var space_press = 0;

function handle_animation(animation_speed);
function rotate_entity(rotate_angle,rotate_speed);

function rotate_entity(rotate_angle,rotate_speed)
{
// result replaced by var rotate_result to prevent conflicts
// ..
var rotate_result;

if (my.pan == rotate_angle) { return; }
rotate_result = ang(rotate_angle - my.pan);
if (rotate_result > 0){
c_rotate(my,vector(rotate_speed * time_step,0,0),IGNORE_PASSABLE);
}
if(rotate_result < 0){
c_rotate(my,vector(-rotate_speed * time_step,0,0),IGNORE_PASSABLE);

}
if (ang(rotate_angle - my.pan) < 0 && rotate_result > 0){
c_rotate(my,vector(rotate_angle - my.pan,0,0),IGNORE_PASSABLE);
}
if (ang(rotate_angle - my.pan) > 0 && rotate_result < 0){
c_rotate(my,vector(rotate_angle - my.pan,0,0),IGNORE_PASSABLE);
}
}

function handle_gravity()
{
//IGNORE_ME|IGNORE_PASSABLE|USE_AABB|USE_BOX
//IGNORE_ME|IGNORE_PASSABLE|USE_POLYGON
//IGNORE_ME|IGNORE_PASSABLE
result = c_trace(vector(my.x,my.y,my.z-6),vector(my.x,my.y,my.z -4000),IGNORE_ME|IGNORE_PASSABLE|USE_AABB|USE_BOX);

if(result < 3) // def: 3
{
if(my.jumping_mode == 0)
{
my.force_z = -1 * result; // def: force_z = -1;
if(key_space == 0 && space_press == 1)
{
space_press = 0;
}
if(key_space == 1 && space_press == 0 && my.animblend >= stand && my.animblend != jump && my.animblend != fall)
{
space_press = 1;
my.jumping_mode = 1;
my.force_z = 25; //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(my.jumping_mode == 2)
{
if(result > 120)
{
my.animate = 60;
my.jumping_mode = 3;
}
else
{
my.jumping_mode = 0;
}
}

if(my.jumping_mode == 3 && result <= 120) // def: 120
{
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_step;
my.force_z = maxv(-30,my.force_z); // def: maxv(-30,my.force_z);
}

my.velocity_z += (time_step * my.force_z) - (minv(time_step*0.7,1) * my.velocity_z);
my.move_z = my.velocity_z * time_step;
}

function handle_movement()
{
VECTOR temp;
temp.x = -1000; // def: temp.x = -1000;
temp.y = 0;

if(key_w == 1 && key_s == 0 && key_a == 0 && key_d == 0) { temp.x = camera.pan; }
if(key_s == 1 && key_w == 0 && key_a == 0 && key_d == 0) { temp.x = camera.pan + 180; }
if(key_a == 1 && key_s == 0 && key_w == 0 && key_d == 0) { temp.x = camera.pan + 90; }
if(key_d == 1 && key_s == 0 && key_a == 0 && key_w == 0) { temp.x = camera.pan - 90; }
if(key_w == 1 && key_a == 1 && key_d == 0 && key_s == 0) { temp.x = camera.pan + 45; }
if(key_w == 1 && key_d == 1 && key_a == 0 && key_s == 0) { temp.x = camera.pan - 45; }
if(key_s == 1 && key_a == 1 && key_d == 0 && key_w == 0) { temp.x = camera.pan + 135; }
if(key_s == 1 && key_d == 1 && key_a == 0 && key_w == 0) { temp.x = camera.pan - 135; }
if(temp.x != -1000) // def: (temp.x != -1000)
{
if(key_shift == 1)
{
temp.y = 10 * time_step;
}
else
{
temp.y = 15 * time_step;
}
}

my.move_x = fcos(temp.x,temp.y);
my.move_y = fsin(temp.x,temp.y);
//USE_AABB|IGNORE_PASSABLE|GLIDE
//IGNORE_PASSABLE|GLIDE
c_move(my,nullvector,my.move_x,USE_AABB|IGNORE_PASSABLE|GLIDE);

//USE_AABB|IGNORE_ME|IGNORE_PASSABLE|USE_BOX
//IGNORE_ME|IGNORE_PASSABLE|USE_POLYGON
//IGNORE_ME|IGNORE_PASSABLE
result = c_trace(vector(my.x,my.y,my.z-6),vector(my.x,my.y,my.z-4000),IGNORE_ME|IGNORE_PASSABLE|USE_AABB|USE_BOX);
if(result < 0) { my.z -= result; my.velocity_z = 0; }
if(temp.y > 0)
{
rotate_entity(temp.x,20); // def: temp.x,20
}

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;
}
}
}

function handle_camera()
{
fixed temp;
var camera_distance = 200; // def: 200 distance camera is from player
camera.pan -= mouse_force.x * 12 * time_step;
camera.tilt += mouse_force.y * 8 * time_step;
camera.tilt = clamp(camera.tilt,-30,10);
temp = fcos(camera.tilt,-camera_distance);
vec_set(camera.x,vector(my.x + fcos(camera.pan,temp),my.y +
fsin(camera.pan,temp),my.z + 20 + fsin(camera.tilt,-camera_distance)));
}




smile
Re: using c_rotate... [Re: D3D] #182873
02/10/08 15:38
02/10/08 15:38
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
Yeah...I use now c_trace/c_move/c_rotate only and everything works well so far I use "c_setminmax(me); wait(1);" at the begining of every acting entity and the c_move/c_rotate mode is "ignore_passable + ignore_passents + ignore_me + glide"

Actualy I use only the animation blending from kh-movement code...I'm working on a simple and easy modable close combat template wich I might release soon (free!)

Re: using c_rotate... [Re: Loopix] #182874
02/10/08 16:00
02/10/08 16:00
Joined: Feb 2008
Posts: 337
V
Vadim647 Offline
Senior Member
Vadim647  Offline
Senior Member
V

Joined: Feb 2008
Posts: 337
It's not so needed to use wait(1); then. It works correct even without it.


I switched to other account since marth 2010. Guess which.
Re: using c_rotate... [Re: Loopix] #182875
02/10/08 16:29
02/10/08 16:29
Joined: Apr 2006
Posts: 1,551
Netherlands
D3D Offline
Serious User
D3D  Offline
Serious User

Joined: Apr 2006
Posts: 1,551
Netherlands
Thanks again. Have hard time with understanding the collision system. Tried replacing the USE_AABB with those commands you've used. And it works although I can't jump anymore. Looking forward to your release. Perhaps I can use that for learning

Removed the wait(1); before c_setminmax(me), but is this not required if you set symetric box of the model? With A7.08.0 beta i've got some strange results after removing USE_AABB and setting GLIDE (camera/player keeps jumping) enable_polycollision is set to 2 as i'm also using physics. Will keep trying though.


smile

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