gun accuracy script? i need help...


(ineedanewbi) #1

hey, i know almost nothing about python, so im gonna need the communities help

right now i have my obj. with an ipo which turns left and right 5 degrees, but no up and down inaccuracy

the job
can someone please make me a script where and obj. will turn or rotate within 5 degrees of its Z and X axis Randomly?

and for other more inaccurate guns, 10 degrees?

that would be great, thanks


(Pooba) #2

Python isn’t needed for this.
I made an example, here it is: www.gratisweb.com/pooba/inacuracy.blend

Hope that helps

Also note that 5 degrees is a LOT for inacuracy (you can see it in my example). 2 degrees might be more plausable.

Pooba


(ineedanewbi) #3

actually thats what i did, but theres a flaw… and an obvious one too…

i want inaccuracy verticaly too, i think it would be easier with python cuz u dont need another obj witha another ipo and the bricklogic etc…


(Pooba) #4

I did make it with verticle. It’s in another scene. Change scene to horizontal and vert.

Pooba


(lizard809) #5

we have a python based inaccuracy script that changes the accuracy based on active weapon, feet on ground, ducking, and running speed. so im not sure this is exactly what you want because of all the inputs. i’ll make a new one that changes the inaccuracy based on a prop called acc, that way you can deal with it easier. are using a ray sensor type shot system?


(ineedanewbi) #6

well, i didnt really expect this to be such a BIG thing
i just want a simple simple script, where ducking and running dont make a difference

BUT i want the script to be easy to tweak, so that i can change it for different weapons, to have it change within X degrees… aprox 5 to 10
just have a Drot(xyz)
where xyz are random between certain numbers to keep in the 5 to 10 degrees thing.

to pooba:
whoops… didnt see the other scene…


(Pooba) #7

My way is pretty easy to modify. All you have to do is change the animation a bit as long as it’s in between frames 1 and 5. If you wanted more frames from that you can change that and the int uniform acuator on the gun and it’s empty.

Pooba


(lizard809) #8

ok, the property “ang” is the max angle of inaccuracy

http://mysite.iptic.com/cluh/inacc.blend

i hope you can figure this out


(ineedanewbi) #9

thanks all… they were both very nice

actually i dont want to be too increadibly picky… but i probably should have said this before… sorry

isnt there a way in python to make an obj turn to a certain possition?.. i know u can make an obj go to an EXACT location u want it to, but what about rotation? can u make an obj. turn to an exact rotation?, just make the values of the obj.s Z and X axis random between certain values(also a varable(s) easy to change)

can i not give my obj and ipo and properties and all that other junk

i was wondering if anyone could make JUST a python script work with one controller and one sensor (always) …

if someone could make a script like that, no ipo, no prop, no additional obj.s etc, just an always sensor and a python controller, that would be great

if u guys dont mind… could u guys try to make this script for me?
thanks…


(lizard809) #10

ok…
you cant just rotate an object in python with XYZ, you have to use a “rotation matrix”. it’s quite a tricky deal and frustrates me because its confusing and python cant multiply a set of matrices with normal commands. but because im nice i made a script that just skews the object so it will work with ray sensors (are you using a ray sensor shooting system?). the “ang” property is the maximum angle of inaccuracy. im using a circular random, non a square one.

http://mysite.iptic.com/cluh/inaccnew.blend


(Ben) #11

-This script attached to a sensor rotates an object 10 degrees(angle=10)
in y-axis

import GameLogic
from math import *
cont=GameLogic.getCurrentController()
own=cont.getOwner()

######## Matrix2Euler ########
mat = own.getOrientation()
size = [1,1,1]
def mat2euler(mat, size): 
	scale = [0.0, 0.0, 0.0] 
	if size[0]!=0.0: 
		scale[0] = 1.0/size[0] 
	if size[1]!=0.0: 
		scale[1] = 1.0/size[1] 
	if size[2]!=0.0: 
		scale[2] = 1.0/size[2] 
	angle_y = -asin(mat[0][2] * scale[0]) 
	C = cos(angle_y) 
	if abs(angle_y)>1.0e-10: 
		C = 1.0/C 
		angle_x = atan2((mat[1][2] * scale[1]) * C, (mat[2][2] * scale[2]) * C) 
		angle_z = atan2((mat[0][1] * scale[0]) * C, (mat[0][0] * scale[0]) * C) 
	else: 
		angle_x = 0.0 
		angle_z = -atan2((mat[1][0] * scale[1]), (mat[1][1] * scale[1])) 
	return (angle_x, angle_y, angle_z)

######## Euler2Matrix ########
def euler2mat(rot_x,rot_y,rot_z):
	A = cos(rot_x)
	B = sin(rot_x)
	C = cos(rot_y)
	D = sin(rot_y)
	E = sin(rot_z)
	F = cos(rot_z)
	AD = A * D
	BD = B * D
	ori = [[C*E,-C*F,-D],[-BD*E+A*F,BD*F+A*E,-B*C],[AD*E+B*F,-AD*F+B*E,A*C]]
	return (ori)


rot = mat2euler(mat,size)
rot_x = rot[0]
rot_y = rot[1]
rot_z = rot[2]


######## Get Sensors ########
sensorlist = cont.getSensors()
s0 = sensorlist[0]


######## Are the keys pressed ########
if s0.isPositive():s0 = 1

######## Functions ########
#rotated by 10 degrees
angle = 10
if s0 == 1:
	rot_y = rot_y + angle * pi / 180
	ori = euler2mat(rot_x,rot_y,rot_z)
	own.setOrientation(ori)
	
			

Ben


(ineedanewbi) #12

hey, thanks every1… if anyone else is looking for a good way to create inaccuracy, i would suggest that u try lizard809’s NEW script, its probably the easiest and most effective script to use.

thanks again everyone