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 (TedMar, VoroneTZ), 1,317 guests, and 4 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
Page 1 of 2 1 2
smooth rotate #184961
02/21/08 23:34
02/21/08 23:34
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
I have problems achieving a smooth rotation My entity is sending out two traces in an angle. Now if something 's hit, the entity should rotate accordingly (object avoidance!). Somehow I still get shaky waggling movements when my entity moves towards the destination.
I'd be glad for any advices to do better

Here's the part of the code:
Code:


//do the turning
vec_diff(face_pos,my.x,my.check_x);
vec_to_angle(face_ang, face_pos);
face_trn.pan = ang(my.pan - face_ang.pan);

if (face_trn.pan > 0)
{
my.face_speed_x = min(my.face_speed_x + 10*time_step, face_speed);
c_rotate(my,vector(my.face_speed_x*time_step,0,0),ignore_passable + ignore_passents + ignore_me + glide);
}
if (face_trn.pan < 0)
{
my.face_speed_x = max(my.face_speed_x - 10*time_step, -face_speed);
c_rotate(my,vector(my.face_speed_x*time_step,0,0),ignore_passable + ignore_passents + ignore_me + glide);
}
if (my.face_speed_x > 0) {my.face_speed_x = max(my.face_speed_x - time_step, 0);}
if (my.face_speed_x < 0) {my.face_speed_x = min(my.face_speed_x + time_step, 0);}



Re: smooth rotate [Re: Loopix] #184962
02/22/08 02:59
02/22/08 02:59
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
Try this:

define face_speed_x2, skill__;
define turn_speed, 2; // ?

Code:

//do the turning
vec_diff(face_pos,my.x,my.check_x);
vec_to_angle(face_ang, face_pos);
face_trn.pan = ang(my.pan - face_ang.pan);

if (face_trn.pan > 0)
{my.face_speed_x = min(my.face_speed_x + 10*time_step, face_speed);}
if (face_trn.pan < 0)
{my.face_speed_x = max(my.face_speed_x - 10*time_step, -face_speed);}

my.face_speed_x2 += clamp(my.face_speed_x - my.face_speed_x, -turn_speed*time_step, turn_speed*time_step);
c_rotate(my,vector(my.face_speed_x*time_step,0,0),ignore_passable + ignore_passents + ignore_me + glide);

if (my.face_speed_x > 0) {my.face_speed_x = max(my.face_speed_x - time_step, 0);}
if (my.face_speed_x < 0) {my.face_speed_x = min(my.face_speed_x + time_step, 0);}



...Haven't tested it, but it should work. Just adjust the turn speed

And the textbox needs to be larger. I can't really read wwhat I reposted


xXxGuitar511
- Programmer
Re: smooth rotate [Re: xXxGuitar511] #184963
02/22/08 05:10
02/22/08 05:10
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
nope...now my entities just pan around them selfes any other sugestion?

Re: smooth rotate [Re: Loopix] #184964
02/22/08 07:31
02/22/08 07:31

A
Anonymous
Unregistered
Anonymous
Unregistered
A



Is this a snippet of the code you sent me 2 months ago?
I would suggest to solve this not by short-distance recognation and turning but with long-distance recognation and calculating a valid path for the entities.



black=block
red=pathwalker
green=destination
blue=long range path scan
lila=valid path
yellow=smoothed path of the pathwalker

mercuryus

Re: smooth rotate [Re: ] #184965
02/22/08 21:19
02/22/08 21:19
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
yes..I think it's the snippet I sent you

your method looks interesting but this would require too many traces...and it's too complicated for my knowledge

my simple short distance avoidance trace works just right for my needs...I' d really only need that rotation part fixed!

thanks anyway for your effort!

Re: smooth rotate [Re: Loopix] #184966
02/23/08 08:21
02/23/08 08:21
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
I'll be really busy next couple days, but if I find time, I'll get it done for you. I did the same thing for Raiden with his obstacle avoidance...


...wait, wasn't that for you


xXxGuitar511
- Programmer
Re: smooth rotate [Re: xXxGuitar511] #184967
02/23/08 09:43
02/23/08 09:43
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
Quote:

I'll be really busy next couple days, but if I find time, I'll get it done for you. I did the same thing for Raiden with his obstacle avoidance...
...wait, wasn't that for you




It was...but who cares...everything cool people do, they do for me

Re: smooth rotate [Re: Loopix] #184968
02/23/08 10:21
02/23/08 10:21
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
I always use this method to achieve a smooth angle interpolation which also avoids gimbal lock.

Code:
// For you rheader file:

// Used by "ang_lerp" (Lite-C doesn't support static yet)
VECTOR ANG_LERP_VEC;

// For your code file:

//--------------------------------------------------------------------
// ANGLE INTERPOLATION
// Like vec_lerp but for angles. Circumvents the gimbal lock issue.
//
// params: resultVec - vector which will receive the result angle
// srcVec - start angle of interpolation
// destVec - destionation angle of interpolation
// blendFactor - [0..1], interpolation factor
//
// returns: result angle (as it will be copied into reultVec)
//--------------------------------------------------------------------
VECTOR* ang_lerp (VECTOR* resultVec, VECTOR* srcVec, VECTOR* destVec, var blendFactor)
{
vec_set(resultVec, srcVec); // Copy source into result
vec_diff(ANG_LERP_VEC, destVec, resultVec); // Difference vector

ANG_LERP_VEC.x = ang(ANG_LERP_VEC.x); // Adjust angle validity
ANG_LERP_VEC.y = ang(ANG_LERP_VEC.y);
ANG_LERP_VEC.z = ang(ANG_LERP_VEC.z);

vec_scale(ANG_LERP_VEC.x, blendFactor); // Interpolate the rotation
vec_add(resultVec, ANG_LERP_VEC); // Apply interpolated angle

return(resultVec); // Return result angle
}



Do not worry about the fact that all parameters are VECTOR*'s, because Vectors and angles share the same structured data (3 vars in a row). In Lite-C this is no problem. It will be easy for you to convert this piece to C-Script. For speed reasons I use a global here, because Lite-C doesn't allow real statics yet.

Example:
Code:
VECTOR vecTemp;
vec_to_angle(vecTemp, vec_diff(vecTemp, you.x, my.x)); // Angle from me to you
ang_lerp(my.pan, my.pan, vecTemp, 0.1 * time_step); // Turn to you softly



Re: smooth rotate [Re: HeelX] #184969
02/23/08 15:13
02/23/08 15:13
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
just a sidenote: don't you place interface stuff into header files? so move the variable declaration into your code file and a function prototype into your header file.

Re: smooth rotate [Re: Joey] #184970
02/23/08 18:22
02/23/08 18:22
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
Thanks...it's a cool snippet and I could translate it to c-script! Though it diden't solve my issue...the way I'm tracing probable causes the problem...

I post some more code here...hoping for a solution
Code:


function ang_lerp(&resultVec,&srcVec,&destVec,blendFactor)
{
var lerp_vec_ang[3];

vec_set(resultVec, srcVec); // Copy source into result
vec_diff(lerp_vec_ang.pan, destVec, resultVec); // Difference vector

lerp_vec_ang.pan = ang(lerp_vec_ang.pan); // Adjust angle validity
lerp_vec_ang.tilt = 0;//ang(lerp_vec_ang.tilt);
lerp_vec_ang.roll = 0;//ang(lerp_vec_ang.roll);

vec_scale(lerp_vec_ang.pan, blendFactor); // Interpolate the rotation
vec_add(resultVec, lerp_vec_ang.pan); // Apply interpolated angle

return(resultVec); // Return result angle
}

function trace_angle(dist,ang_dist)
{
my.check_x = my.x + fcos(my.pan+ang_dist,dist);
my.check_y = my.y + fsin(my.pan+ang_dist,dist);
my.check_z = my.z + 10;

return(c_trace(my.x,my.check_x,ignore_me + ignore_passable + ignore_passents + ignore_sprites));
}

function avoid_obstacle(&vec)
{
var face_pos[3];//used to set position then distance

var dist1;
var dist2;

var dist3;

var turn_state;
turn_state = 0;

// this is for normal turning to the player
if(turn_state == 0){
vec_diff(face_pos,my.x, vec.x);

dist1 = trace_angle(my.obj_avoid_trace_dist,-my.obj_avoid_ang_dist); // right angle checking
dist2 = trace_angle(my.obj_avoid_trace_dist,my.obj_avoid_ang_dist); // left angle checking

if(dist1 == 0 && dist2 == 0){
dist3 = (c_trace(vector((my.x + cos(my.pan) * (my.max_x + (my.obj_avoid_trace_dist/2))),(my.y + sin(my.pan) * (my.max_x + (my.obj_avoid_trace_dist/2))),my.z + (my.max_z)),vector((my.x + cos(my.pan) * (my.max_x + (my.obj_avoid_trace_dist/2))),(my.y + sin(my.pan) * (my.max_x + (my.obj_avoid_trace_dist/2))),my.z - (my.max_z + (my.max_z/1.5))),ignore_me + ignore_passable + ignore_passents + ignore_sprites + use_box));

vec_diff(temp,vector((my.x + cos(my.pan) * (my.max_x + (my.obj_avoid_trace_dist/2))),(my.y + sin(my.pan) * (my.max_x + (my.obj_avoid_trace_dist/2))),my.z + (my.max_z)),vector((my.x + cos(my.pan) * (my.max_x + (my.obj_avoid_trace_dist/2))),(my.y + sin(my.pan) * (my.max_x + (my.obj_avoid_trace_dist/2))),my.z - (my.max_z + (my.max_z/1.5))));//store difference of distance in temp


if(dist3 > (my.max_z * 2) && normal.z < 0.8 || normal.z > 1.2){
if (my.f_animblend != f_stand)
{
my.f_blendframe = f_stand;
}
my.speed_x = 0;
}
if(dist3 > ((my.max_z - my.min_z)/4) && dist3 < ((my.max_z - my.min_z)/2.75) && you != player){
jumping();
}
}
}

// alter states if dist1 or dist2 returns > 0
if(dist1 > 0 && turn_state == 0){turn_state = 1;}
if(dist2 > 0 && turn_state == 0){turn_state = 2;}


if(turn_state == 1){
dist1 = trace_angle(my.obj_avoid_trace_dist,my.obj_avoid_ang_dist);
vec_diff(face_pos,my.x,my.check_x);
if(dist1 == 0){turn_state = 0;} // back to normal state
}

if(turn_state == 2){
dist1 = 0;
dist2 = trace_angle(my.obj_avoid_trace_dist,-my.obj_avoid_ang_dist);
vec_diff(face_pos,my.x,my.check_x);
if(dist2 == 0){turn_state = 0;} // back to normal state
}

//do the turning
vec_to_angle(temp.pan, face_pos.x); // Angle from me to you
ang_lerp(my.ang_force_pan, my.pan, temp.pan, 0.8 * time_step); // Turn to you softly


}



The "my.ang_force_pan" is then used in c_rotate of the enemy action

Page 1 of 2 1 2

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