Gamestudio Links
Zorro Links
Newest Posts
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
4 registered members (degenerate_762, AbrahamR, AndrewAMD, ozgur), 667 guests, and 8 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
Smooth rotation fails in one out of two cases #212707
06/23/08 20:06
06/23/08 20:06
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline OP
Expert
Xarthor  Offline OP
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Hi,
I use the following snippet to smoothly turn entities:
Code:
var ship_rotateSpeed = 6;

function game_SmoothRotateToPos(&_pos)
{
	var target_vec[3];
	var angle[3];
	
	vec_set(target_vec,_pos);
	
	vec_diff(target_vec, target_vec, my.x);
	vec_to_angle(angle, target_vec);
	
	while(abs(my.pan-angle.pan) > ship_rotateSpeed)
	{
		if(ang(angle.pan - my.pan) < 0)
		{
   		my.pan -= clamp(abs(ang(angle.pan - my.pan)),0,ship_rotateSpeed) * time_step;
		} 
		else 
		{
	   	my.pan += clamp(abs(ang(angle.pan - my.pan)),0,ship_rotateSpeed) * time_step;
		}
		
		wait(1);
	}
	my.pan = angle.pan;
}


Now this works fine if the start pan of the entity is equal to zero.
However if the start pan is 180, it rotates but does not finish the rotation.
Instead it stops shortly before finishing it and never exists that while loop.

Anyone know why this happens?

Thanks in advance for any hints.

Re: Smooth rotation fails in one out of two cases [Re: Xarthor] #212728
06/23/08 23:02
06/23/08 23:02
Joined: May 2006
Posts: 90
England
TigerTao Offline
Junior Member
TigerTao  Offline
Junior Member

Joined: May 2006
Posts: 90
England
Its possible that the ship has hit the 180/-180 threshold and is stuck moving between going +pan/-pan. I've had trouble with using "ang" before.

However there is a very good solution to shortest angle rotation here:

http://www.coniserver.net/ubb7/ubbthreads.php?ubb=showflat&Number=201834

Yuo can also use testDummy's (thanks to him by the way) even shorter version of that:

var rotSp[3] = 20, 0, 0; // rotate speed
var vec_to_target[3];
var ang_to_target[3];

vec_diff(vec_to_target, player.x, my.x); // direction vector from my to you
vec_to_angle(ang_to_target, vec_to_target); // get angles of direction vector
temp[0] = ang(ang_to_target.pan - my.pan);
my.pan += min(rotSp.pan * time_step, abs(temp[0])) * sign(temp[0]);

Hope this helps.

Re: Smooth rotation fails in one out of two cases [Re: TigerTao] #212792
06/24/08 08:03
06/24/08 08:03
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline OP
Expert
Xarthor  Offline OP
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Thanks TigerTao!
I figured it out and now got it working all nicely smile

Thanks again!


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