logo
Main

Forums

Downloads

Unreal-Netiquette

Donate for Oldunreal:
Donate

borderline

Links to our wiki:
Wiki

Walkthrough

Links

Tutorials

Unreal Reference

Usermaps

borderline

Contact us:
Submit News
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Scriptedpawn random wandering (Read 2438 times)
asgard12000
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 254
Joined: Aug 15th, 2005
Scriptedpawn random wandering
Aug 8th, 2009 at 4:10am
Print Post  
The current coding for scriptedpawn while in state wandering doesnt do true random wandering.

It has 30% chance to go in direction X
or it has 30% chance to go in direction Y
or it has 40% chance to go in any direction (which has a 50% change to favor the above diections)

Meaning that the majority of the time it will end up in a cross vector between X and Y

An example of this is if you summon a warlord in spirevillage (near where you first enter the map) and drop a krall on his head. He will kill the krall and go into state wandering as theres no pathnode close by

Eventually he will always end up in the bottom corner of the map and never come out.

To have true wandering the code needs to be changed from
THIS

Code
Select All
	function PickDestination()
	{
		local vector pick, pickdir;
		local bool success;
		local float XY;
		//Favor XY alignment
		XY = FRand();
		if (XY < 0.3)
		{
			pickdir.X = 1;
			pickdir.Y = 0;
		}
		else if (XY < 0.6)
		{
			pickdir.X = 0;
			pickdir.Y = 1;
		}
		else
		{
			pickdir.X = 2 * FRand() - 1;
			pickdir.Y = 2 * FRand() - 1;
		}
		if (Physics != PHYS_Walking)
		{
			pickdir.Z = 2 * FRand() - 1;
			pickdir = Normal(pickdir);
		}
		else
		{
			pickdir.Z = 0;
			if (XY >= 0.6)
				pickdir = Normal(pickdir);
		}

		success = TestDirection(pickdir, pick);
		if (!success)
			success = TestDirection(-1 * pickdir, pick);

		if (success)
			Destination = pick;
		else
			GotoState('Wandering', 'Turn');
	}

 



To THIS
Code
Select All
	function PickDestination()
	{
	   local vector pick, pickdir;
	   local bool success;
	   local float XY;

       	   pickdir.X = 2 * FRand() - 1;
	   pickdir.Y = 2 * FRand() - 1;
       	   pickdir.Z = 2 * FRand() - 1;
                   if (Physics == PHYS_Walking)
                       pickdir.Z = 0;
       	   pickdir = Normal(pickdir);

	    success = TestDirection(pickdir, pick);
	    if (!success)
	        success = TestDirection(-1 * pickdir, pick);

	    if (success)
	        Destination = pick;
	    else
	        GotoState('Wandering', 'Turn');
	}
 




Cheers


« Last Edit: Aug 8th, 2009 at 5:22am by asgard12000 »  
Back to top
 
IP Logged
 
.:..:
Board Moderator
Developer Team
*****
Offline



Posts: 1463
Location: Finland
Joined: Aug 16th, 2005
Gender: Male
Re: Scriptedpawn random wandering
Reply #1 - Aug 8th, 2009 at 7:39am
Print Post  
Correction:
Code
Select All
	function PickDestination()
	{
		local vector pick, pickdir;
		local bool success;

		pickdir.X = 2 * FRand() - 1;
		pickdir.Y = 2 * FRand() - 1;
		if (Physics != PHYS_Walking)
		{
			pickdir.Z = 2 * FRand() - 1;
			pickdir = Normal(pickdir);
		}
		else if( FRand()>=0.6 && (pickdir.X*pickdir.X+pickdir.Y*pickdir.Y)>0.01 )
			pickdir = Normal(pickdir);

		success = TestDirection(pickdir, pick);
		if (!success)
			success = TestDirection(-1 * pickdir, pick);

		if (success)
			Destination = pick;
		else GotoState('Wandering', 'Turn');
	} 


just in case...
  

Shivaxi wrote on Jul 25th, 2013 at 12:50pm:
...and now im stuck trying to fix everything you broke for the next 227 release xD Tongue

(ಠ_ಠ)
Back to top
IP Logged
 
asgard12000
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 254
Joined: Aug 15th, 2005
Re: Scriptedpawn random wandering
Reply #2 - Aug 8th, 2009 at 9:38am
Print Post  
In case of what? I dont see the point to this code
Code
Select All
else if( FRand()>=0.6 && (pickdir.X*pickdir.X+pickdir.Y*pickdir.Y)>0.01 )
			pickdir = Normal(pickdir);
 

« Last Edit: Aug 8th, 2009 at 11:09am by asgard12000 »  
Back to top
 
IP Logged
 
Bane
Senior Member
****
Offline



Posts: 496
Joined: Mar 3rd, 2002
Gender: Male
Re: Scriptedpawn random wandering
Reply #3 - Aug 8th, 2009 at 5:12pm
Print Post  
That looks like a check to make sure you don't try to take the normal of vect(0,0,0). Doing that would involve division by 0 and is therefore undefined, so it should be avoided. Although I don't know why Dots doesn't just compare it to vect(0,0,0). My UScript is rusty, but doesn't that work fine? Also, there's no correction of any kind if that check does fail.
  

Author of Hide and Seek mod, and the NALIBALL mod&&&&Hide and Seek can be downloaded from:&&http://HideNSeek.5u.com
Back to top
AIM  
IP Logged
 
asgard12000
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 254
Joined: Aug 15th, 2005
Re: Scriptedpawn random wandering
Reply #4 - Aug 9th, 2009 at 12:48am
Print Post  
Still doesnt make sense. It only checks the code 40% of the time so it would still fail. It also "only" normalizes positive vectors and not negatives depending on what the sum adds up to. Whos to say X doesnt equal -0.8 and Y = 0.2. etc  

For a vector check.. The code should be

Code
Select All
    function PickDestination()
    {
	 local vector pick, pickdir;
	 local bool success;

	 pickdir.X = 2 * FRand() - 1;
	 pickdir.Y = 2 * FRand() - 1;
	 pickdir.Z = 0;

	 if (Physics != PHYS_Walking)
	  pickdir.Z = 2 * FRand() - 1;

	 if ( pickdir == Vect(0,0,0) )
	   pickdir=Vector(Rotation);

	 pickdir = Normal(pickdir);
	 if ( pickdir == Vect(0,0,0) )
	   pickdir.X = 1;
	 success = TestDirection(pickdir, pick);
	 if (!success)
	  success = TestDirection(-1 * pickdir, pick);

	 if (success)
	  Destination = pick;
	 else
	  GotoState('Wandering', 'Turn');
    }
 





« Last Edit: Aug 9th, 2009 at 2:03am by asgard12000 »  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint
Bookmarks: del.icio.us Digg Facebook Google Google+ Linked in reddit StumbleUpon Twitter Yahoo