Game Development Community

Firing accuracy and World Scale

by Nicholas Arellano · in Torque Game Builder · 06/03/2005 (8:44 am) · 7 replies

I have two questions that I have been wrestling with.

1: Is there a way to build in a probabily of a projectile missing the mark by a random percentage? I'll try to explain: I am making a soccer game and I am thinking that the passing and shooting can be done in the same manner that the ship fires rockets in the tutorial. Basically a new sprite (in this case the ball) would be created when it is passed or shot. The only difference would be that the pass or shot would be aimed at a specific world coordinate (xy) on the soccer field (where the play clicks the mouse). I want to build in the influences of variable human skill and difficulty of task in determining the probability of the ball hitting the target or coming close. For example a skilled player would complete the pass within a certain margin of error and a less skilled player would complete the pass within a larger margin of error. The margin of error would be defined by the number of xy coordinates the ball goes from the intended xy coordinate. The skilled player's pass would land some where within a random xy coordinate of, let's say, 5 away from target and a less skilled player would have his pass land within 10 xy coordinates. It would be random because sometimes the player puts a little too much touch on the ball or a little less. I am hoping that one of you guys have some insight from your experience in dealing with the accuracy of different types of weapons.

2: How far is a world unit? If a sprite is moving 10 world units a second how far is it moving and how can this be set? This is similar to the first question. Players react at different speeds (depending on askill and physical factors) so I'd like to have a similar randomized approach to how far players move in reaction to a pass or shot.

This is a turn based game but I guess the solution could be applied to a simulation. So far I am at the point of being able to move all the players with the mouse.

#1
06/03/2005 (9:27 am)
1. Don't see why not. You have already stated how it could be done with a modifier being applied to the target x/y coords based on the players skill.

2. 10 world units will always be 10 world units, but the number of pixels in a world unit will change as the resolution changes. Again, speed could be controlled by a modifier. All players could move at a speed of 10. Faster players would have a modifier added, slower players would have it subtracted.

With a lot of things, you need to trial and error a few settings to see how it feels. I know I spend a reasonable amount of time tweaking the speeds of various objects until they feel right and are moving at a speed relative to what the object is, and the other objects around it.
#2
06/03/2005 (9:33 am)
What I would do for 1. would be to throw the margin of error modifying the angle against a random value, that way the more skilled the "tighter" the cone of passing and shooting would be, while the unskilled the larger the cone of error would be.

2. Philip hit it righ ton, a lot of it is just getting the right "feel"... thats when it helps to set up some gui controls to easily modify speed and variables, make things data driven so you can modify and tweak them easily and see the different real time. My Physics Demo came in handy for that since I can test the effect of different physics properties fairly easily.
#3
06/03/2005 (12:01 pm)
Thanks guys.

1. Is there a tutorial or an example of how "to throw the margin of error modifying the angle against a random value"?

2. Feel is good. I just wanted to get an idea. I found a thread asking the same question but it said that I didn't have the ability to read it because I didn't own the correct program. I only have a license for T2D. I'll be moving to the other program once I get comfortable with the 2D stuff.

I am a noob programer at this level and I enjoy getting into the code and trying to figure it out. Being a noob I use the tutorials as a starting point and adapt the way it is executed to achieve what I want. Hence using the firing sequence for passing a ball around. So far I have it so that the complexMouse system workers for all the different players and ball on the screen and I am trying to figure out how to apply the pathMoving extention of that. I probably won't need it in my game but if I have it available it might come in handy as the game play system evolves.

So thanks for any insight. It might sound a little crazy to you but my first commercial product using this program might not even be a game but a coaching tool.
#4
06/03/2005 (12:16 pm)
Hmmm margin of error + random angle... maybe something like this

// out of 100
%skill = 50; 
 
//test, would be the angle of targe  here
%angle  = 45; 


//in this case %skillMargin would equal "5"
%skillMargin = (100 - %skill) / 10; 


//in this case %angleMin would equal "40"
%angleMin = %angle - %skillMargin;
//in this case %angleMax would equal "50"
%angleMax = %angle + %skillMargin;


//get a random angle from %angleMin (40) to %angleMax (50)
%fireAngle = (getRandom() * %angleMax) + %angleMin;


btw glad your going through the tuts :) Will help you understand it better and hopefully help you get comfortable enough with the scripting language to become "creative" with it.
#5
06/03/2005 (2:42 pm)
Ahhh OK. I see what you are talking about. The angle is established and then randomized according to skill level, hence the "cone" you referred to. At this point, I think a function needs to be created that establishes the angle and does what you show above.
#6
06/03/2005 (4:20 pm)
function angleBetween(%playerPos, %mousePos)
{
	// Seperate Mouse Position
	%mxpos = getWord(%mousePos,0);
	%mypos = getWord(%mousePos,1);

	// Seperate Player Position
	%px = getWord(%playerPos,0);
	%py = getWord(%playerPos,1);

	// Calculate Angle from player to mouse (convert to degrees).
	%angle = mRadToDeg( mAtan( %mxpos-%px, %py-%mypos ) );

	return %angle;
}

theres a function to get the angle between two points :)
#7
06/03/2005 (4:35 pm)
P.s. I'll let you combine those code snippets into a function and give it a whirl, that way you can figure it out and learn a little more about T2D script manipulation :) Feel free to post more questions though.