setLinearVelocity [addObjectActuator]

hi, im having trouble with “setLinearVelocity [addObjectActuator].” In my original program i had an object [tube] which could be spun with three keys using dRot in a motion LogicBrick. I then had a key which added another object using the edit object-add object actuator, this actuator had the linV of 6,0,0 with the little L clicked in… this caused the added object to be"spat out" of the[tube] in the direction the tube was facing ( maybe it wasnt the direction it was facing but it corresponded to the direction it was facing]

Ive now got midi sorted(it was python2.4 btw) and am rescripting everything in python. Ive got the main object[tube] to spin according to midi cc numbers and to some extent have the add object actuator working, it will add another object but wont spit it out locally, it always goes in the same direction. Ive looked in the API document but apparently setLinearVelocity in the addObjectActuator doesnt have the fourth local property it only has x,y,z, the motion actuator does however have x,y,z,l.

so am i being stupid here or do i have to use something to get the dRot of my main object [the tube] and place this in the setLinearVelocity x,y,z, and keep updating this as my tube spins???

im really tired and properly rambling so if youve got this far well done, heres the code if that helps explain anything

import GameLogic
g=GameLogic
import midipy

cont = GameLogic.getCurrentController()
own = cont.getOwner()

tube = cont.getActuator(“rotx”).getOwner()
cube003 = cont.getActuator(“addCube003”).getOwner()

rotx = cont.getActuator(“rotx”)
roty = cont.getActuator(“roty”)
rotz = cont.getActuator(“rotz”)

#rotxyz = cont.getActuator(“rotxyz”)

addtube = cont.getActuator(“addTube”)
addcube003 = cont.getActuator(“addTube”)

######midi read#####
msg=midipy.returnMidiMsg()
print msg

if msg <>-1:
if msg[0]==1:
g.midiArray[msg[2]]=msg[3]
if msg[2]==1:
own.backRED = msg[3]

		if msg[2]==2:
			own.backGRE = msg[3]
						
		if msg[2]==3:
			own.backBLU = msg[3]
		
		if msg[2]==0:
			own.speed = msg[3]
		
		if msg[2]==4:
			own.mistRED = msg[3]
		
		if msg[2]==5:
			own.mistBLU = msg[3]
			
		if msg[2]==6:
			own.mistGRE = msg[3]
		
		if msg[2]==7:		
			own.mistSTART =msg[3]
		
		############# tube rotation ###########		
		if msg[2]==8:
			rotx.setDRot((msg[3]/100.0),0,0,1)	
		if msg[2]==8 and msg[3]&gt;0:
			GameLogic.addActiveActuator(rotx, 1)
	
		if msg[2]==9:
			roty.setDRot(0,(msg[3] / 100.0),0,1)
		if msg[2]==9 and msg[3]&gt;0:
			GameLogic.addActiveActuator(roty, 1)
	
		if msg[2]==10:
			rotz.setDRot(0,0,(msg[3] / 100.0),1)
		if msg[2]==10 and msg[3]&gt;0:
			GameLogic.addActiveActuator(rotz, 1)
		
	#############addobject##########################		

		if msg[2]==17 and msg[3]==127:
			addcube003.setLinearVelocity(6.5,0,0)
			addcube003.setTime(1000)
			addcube003.setObject(cube003)
			GameLogic.addActiveActuator(addcube003, 1)

if msg[2]==8:

x = msg[3]/100.0

print x

if msg[2]==9:

y = msg[3]/100.0

print y

if msg[2]==10:

z = msg[3]/100.0

print z

rotxyz.setDRot(x,y,z,1)

GameLogic.addActiveActuator(rotxyz, 1)

Well, lol, I’m way too lazy to debug your code as I don’t have the .blend along with the code. So I just made my own little example showing that setLinearVelocity does work.

:wink: Ehh, I hope it helps some. Just shows an object spinning around with dRot. It has an empty parented to it that adds an object that’ll shoot in the local y direction. To show that setLinearVelocity works, I incremented the y velocity each time space was pressed to shoot out the new object.

http://www.antihc3.dyndns.org/blender3dsite/uploads/MISC/SetLinearVelocity.blend

Jason Lin

Thanks :slight_smile: ,
That was me being knakered, i was adding an object to an object in another scene which was not rotating, thats why nothing wss working. Sorted it out now. Cheers for taking the time to unconfuse me.

Will

Is there any way to create a addobjectactuator,

say for a shot gun you want to create 10 or so objects at once, without having to make 10 actuators in the logicbricks? This would be easier and you could have differnt amounts coming out each time.

Probably no other way. But if you wanted to add like 10 objects with 1 add object actuator. Say you wanted to add 10 bullets. Just duplicate like 10 bullets in the 2nd layer. Parent them all to a single object that’ll more or less be in the middle of the whole thing. Have the add object actuator call the parent object and all the other objects that are parented to it will be added in as well.

:smiley:

Jason Lin

There is another option. It requires more python than the previous suggestion but offers more flexibility. Add the object and then send a message that triggers the gun to repeat the process. Have a property to count how many have been added and one to set the maximum to add. When the last has been added don’t send the message to re-trigger the process and no more will be added.

Well the problem with goldentaiji is you have one huge mass moving as same speed and range. I guess you could hvae python randomly add differnt objects so it looked random. still would all move at same speed.

Problem with blane is you would get a machine gun effect, you can’t use on addobjectacutator to add more then on object on the same frame, so still would not get the shotgun effect.

The best way to do it now is just have 10 or so actuators attached to the gun and have them varied. maybe set the velocity to a randome factor each time it shoot ect… change there direction slightly. This is still just a work around for what i want but it seems to be the only way to do it so far. I made a suggestion in the blender.ord 2.41rc2 build forum about python being able to create actuators.

%| Err so adding 10 objects at the same time isn’t what you wanted then? Technically speaking if all objects are shot out at the same time they should have the same speed and velocity. Well… I don’t know my shot guns too well. Basically you could fake the effect by calling the script a set number of times in really short intervals to trigger the addobject actuator to add a bullet. At each instant the script is called use python to randomize the orientation of the empty that will add the bullet. It’ll give it the spread effect that a shot gun might have.

:wink: Dunno why you want to have the shot gun actually shoot bullets out releastically. Frankly speaking they’re too fast for you to see in real life anyhows (hehe, unless you’re going for a matrix effect). I don’t believe I’ve ever seen bullets come out from the shot gun in Halo.

Jason Lin

Good point.

So just using bunch of rays would work to, or even better, one ray and a random looking bulltet hole for the thing it hit.