🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #1823

Re: [pic] avoidance problem

#1823
From: fir
Date: Mon, 23 Nov 2026 22:29
104 lines
4882 bytes
fir pisze:
> imagine you got a flyin ships in space (which may be treated as spheres)
> they got direction and forvard velocity, they may turn yaw/pitch also 
> slow down or accelerate... the yaw pitch slowdown/acceleraty is by 
> applying forces (yaw_force, pitch_force.. and so on, this force is from 
> 0.0 to 1.0 which is max, usualy max is applied and this force gives 
> increases some taw/pitch velocity but there is also damping)
> 
> the problem is i need to vrite a good routine that would make good 
> result in avoiding
> 
> the input is position, radius, direction, forward_velocity for both 
> participants (i mean for each ship i run it in the loop for any other so 
> it make pairs)
> 
> what ai gives me not quite work and this is exampla how working with ai 
> look like, i need myself somewhat rationalize it to find good answer



some idea come to me and ai - not to think in geometry (in which im not 
good) but just count a next point, count a next point if i would turn 
right, left , count a next point if i turn down, up , count next point 
if i speed up,  down -- and chose the point which is most far to 
collision..thats great local simplicity though all those countings are 
sorta heavy




void AvoidSphere(int i, float i_radius, float3 object_pos,float3 
object_velocity,float object_radius)
{
	float3 object_next=add(object_pos,object_velocity);

	float avoid_radius=object_radius + i_radius + AVOID_DISTANCE;

	float3 to_object=sub(object_pos,bag[i].p.pos);
	float distance0=length(to_object);

	if(distance0>=avoid_radius) return;

	bag[i].is_avoiding+=1;

	/* Punkt, w którym statek znajdzie się bez żadnej dodatkowej siły. */
	float3 p0=PredictNextFrameObjectPosition(i,0,0,0,0,0,0);
	float best_distance=distance(p0,object_next);

	float best_yaw=0;
	float best_pitch=0;
	float best_forward=0;

	/* Lewo / prawo. */
	float3 p;
	float d;

	p=PredictNextFrameObjectPosition(i, 1,0,0,0,0,0); 
d=distance(p,object_next);
	if(d>best_distance) { best_distance=d; best_yaw=1; best_pitch=0; 
best_forward=0; }
	p=PredictNextFrameObjectPosition(i,-1,0,0,0,0,0); 
d=distance(p,object_next);
	if(d>best_distance) { best_distance=d; best_yaw=-1; best_pitch=0; 
best_forward=0; }
	p=PredictNextFrameObjectPosition(i,0, 1,0,0,0,0); 
d=distance(p,object_next);
	if(d>best_distance) { best_distance=d; best_yaw=0; best_pitch=1; 
best_forward=0; }
	p=PredictNextFrameObjectPosition(i,0,-1,0,0,0,0); 
d=distance(p,object_next);
	if(d>best_distance) { best_distance=d; best_yaw=0; best_pitch=-1; 
best_forward=0; }
	
	p=PredictNextFrameObjectPosition(i, 1,0,0,1,0,0); 
d=distance(p,object_next);
	if(d>best_distance) { best_distance=d; best_yaw=1; best_pitch=0; 
best_forward=1; }
	p=PredictNextFrameObjectPosition(i,-1,0,0,1,0,0); 
d=distance(p,object_next);
	if(d>best_distance) { best_distance=d; best_yaw=-1; best_pitch=0; 
best_forward=1; }
	p=PredictNextFrameObjectPosition(i,0, 1,0,1,0,0); 
d=distance(p,object_next);
	if(d>best_distance) { best_distance=d; best_yaw=0; best_pitch=1; 
best_forward=1; }
	p=PredictNextFrameObjectPosition(i,0,-1,0,1,0,0); 
d=distance(p,object_next);
	if(d>best_distance) { best_distance=d; best_yaw=0; best_pitch=-1; 
best_forward=1; }


	/* Wybieramy najlepszy ruch. */
	bag[i].yaw_force=best_yaw;
	bag[i].pitch_force=best_pitch;
	bag[i].forward_force=best_forward;
}



also there is case when ships could collide with more things they avoid 
one and just run stright into another and explode ;c

i alos not sure if it behaves well in 1-1 collisions such things are 
quite hard to visually debug
Technical Details
Message-ID: <11e2enj$2a9jv$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11e2610$26vvs$1@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: fir <profesor.fir@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: [pic] avoidance problem
Date: Mon, 23 Nov 2026 23:29:07 +0100
Organization: A noiseless patient Spider
Lines: 104
Message-ID: <11e2enj$2a9jv$1@dont-email.me>
References: <11e2610$26vvs$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 23 Nov 2026 22:29:07 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2434687"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1//CCGBrQxsTzAgSjcSWfAnQ0IZGs6q0MI="; posting-host="cb57700b627c63fdcf4461b50f598e32"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101
 Firefox/140.0 SeaMonkey/2.53.24
Cancel-Lock: sha1:x1r7MGD4SEMEl742LkalAiwCEcE= sha256:W2r3Tyuo6OdfMrhFmCDqhy6MOv7bmEfGGV5KYG/D+EQ=
	sha1:FvSfWKeHoHZYTTYEtafxPb5pC0g= sha256:HR1nZmSqwYzLgB+c96s7CI5UqAAFRb/ydl47LIqggeI=
In-Reply-To: <11e2610$26vvs$1@dont-email.me>