spawn gun aiming
			10 posts			 • Page 1 of 1		
	
spawn gun aiming
i have made a machine gun that spawns .30 cal bullets and every time i want to aim it, it shoots bullets out in the same place every time. can someone give me a code and instructions to fix this? i would appreciate it 
							- Attachments
 - 		
 bullet spawner.phz- (59.83 KiB) Downloaded 51 times
 
 
- bosiefus
 - Posts: 5
 - Joined: Sat Jun 04, 2011 4:58 pm
 
Re: spawn gun aiming
do they spawn at the same point or dont they have any velocity?
if they spawn at the same point you have to go into the spawncode and type in
is it that what you meant?
			if they spawn at the same point you have to go into the spawncode and type in
- Code: Select all
 pos:=e.pos
is it that what you meant?
yup yup 
yuuuuuuup
yupyupyupyupyupyupyupyupyyyuuuup
hm... signatures...
		yuuuuuuup
yupyupyupyupyupyupyupyupyyyuuuup
hm... signatures...
- hiltropper
 - Posts: 85
 - Joined: Mon Dec 20, 2010 12:02 pm
 - Location: Germany
 
Re: spawn gun aiming
not realy, i want it to be aim-able so if i turn the gun up it will shoot that way. just download the scene and you will know what i am talking about
			
		- bosiefus
 - Posts: 5
 - Joined: Sat Jun 04, 2011 4:58 pm
 
Re: spawn gun aiming
It's extremely difficult in general to rotate objects while spawning them. It's doable with a simple box, less so with polygons.
So if that's what you want...ask one of the Gods of Thyme for a function to rotate a polygon. The rest is just trig to figure out the angle based on e.normal—there's sample code all over this forum. Search for "atan".
If you're okay with spawning a textured box instead, it's much simpler, but still not simple. Again you'll need the angle, but if you're just spawning a single box, there's a property (just "angle" I think) that you can use to directly set the angle.
			
		So if that's what you want...ask one of the Gods of Thyme for a function to rotate a polygon. The rest is just trig to figure out the angle based on e.normal—there's sample code all over this forum. Search for "atan".
If you're okay with spawning a textured box instead, it's much simpler, but still not simple. Again you'll need the angle, but if you're just spawning a single box, there's a property (just "angle" I think) that you can use to directly set the angle.
- daniels220
 - Posts: 95
 - Joined: Mon Aug 31, 2009 11:30 pm
 
Re: spawn gun aiming
ok
you take two boxes , the line trough both will be the direction into the bulets fly later
one you give the code onlaserhit=
it should look like
now the direction is right , if they fly too slow , put "5*" or any other in front of the code
the right angle of the bullet itself (not the angle it flies) can be done with math.atan
i will test it and if you have any more question ,ask
[EDIT]
it works
ill upload you a sample scene so you can look at the codes and what i mean with the two boxes
here (it was made with the new 1.9.5 beta , if there are any problems i could make one for the 1.8) :
[EDIT2]: updated it to a bullet surface code that is similar to yours
so you see the only thing you have to mention is : select your bullet, press str+v into any code area and copy the huge matrix that stands behind "surfaces:=" and let this polygon spawn
			you take two boxes , the line trough both will be the direction into the bulets fly later
one you give the code onlaserhit=
- Code: Select all
 scene.my.firstpos=e.pos
- Code: Select all
 scene.my.secpos=e.pos
it should look like
- Code: Select all
 ...
vel:=(scene.my.firstpos-scene.my.secpos);
...
now the direction is right , if they fly too slow , put "5*" or any other in front of the code
- Code: Select all
 vel:=5*(scene.my.firstpos-scene.my.secpos);
the right angle of the bullet itself (not the angle it flies) can be done with math.atan
- Code: Select all
 angle:= math.atan((scene.my.firstpos(1)-scene.my.secpos(1))/(scene.my.firstpos(0)-scene.my.secpos(0)))
i will test it and if you have any more question ,ask
[EDIT]
it works
ill upload you a sample scene so you can look at the codes and what i mean with the two boxes
here (it was made with the new 1.9.5 beta , if there are any problems i could make one for the 1.8) :
[EDIT2]: updated it to a bullet surface code that is similar to yours
so you see the only thing you have to mention is : select your bullet, press str+v into any code area and copy the huge matrix that stands behind "surfaces:=" and let this polygon spawn
yup yup 
yuuuuuuup
yupyupyupyupyupyupyupyupyyyuuuup
hm... signatures...
		yuuuuuuup
yupyupyupyupyupyupyupyupyyyuuuup
hm... signatures...
- hiltropper
 - Posts: 85
 - Joined: Mon Dec 20, 2010 12:02 pm
 - Location: Germany
 
Re: spawn gun aiming
i realy apreciate the help but i cant understand a thing you guys said. 
			
		- bosiefus
 - Posts: 5
 - Joined: Sat Jun 04, 2011 4:58 pm
 
Re: spawn gun aiming
The intention, I think, is to use various methods to spawn a bullet at the right position and with the right velocity.
You can get the angle out of e.normal by this code:
You may need to adjust this code a bit so it actually works. I think it will, but I am not sure. You may need to change the less than to a greater than, or add math.pi at the end, or add (2 * math.pi)...
The velocity of the gun can be calculated by:
This bit goes out of the spawn code. Also put it on an alternating collider. Let me know if you don't know what that is.
This bit goes in the spawn code:
This code will spawn the geom already moving away from whatever spawned it:
However, when you combine the above two codes to get this:
			You can get the angle out of e.normal by this code:
- Code: Select all
 angle := (math.acos(e.normal(1)) * {math.asin(e.normal(0)) < 0} ? {1} : {-1}) - math.pi
You may need to adjust this code a bit so it actually works. I think it will, but I am not sure. You may need to change the less than to a greater than, or add math.pi at the end, or add (2 * math.pi)...
The velocity of the gun can be calculated by:
This bit goes out of the spawn code. Also put it on an alternating collider. Let me know if you don't know what that is.
- Code: Select all
 textureMatrix = [e.pos(0) - textureMatrix(2), e.pos(1) - textureMatrix(3), e.pos(0), e.pos(1), 0.0, 0.0, 0.0, 0.0, 0.0]
This bit goes in the spawn code:
- Code: Select all
 vel := [textureMatrix(0), textureMatrix(1)] * 50
This code will spawn the geom already moving away from whatever spawned it:
- Code: Select all
 vel := e.normal * 100
However, when you combine the above two codes to get this:
- Code: Select all
 vel := ([textureMatrix(0), textureMatrix(1)] * 50) + (e.normal * 100)
Matthias Wandel is epic, in my humble opinion.
I love my brain...
ARE YA HAPPY NOW?????
Thymechanic/Phundamentalist
Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
		I love my brain...
TC42 wrote:Also, your sig is too big, please change it.
ARE YA HAPPY NOW?????
Thymechanic/Phundamentalist
Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
- 
				

Someone Else - Posts: 1147
 - Joined: Sun Nov 21, 2010 10:53 pm
 - Location: The Milky Way Galaxy
 
Re: spawn gun aiming
my method is actually not more than geometry...you use only two points for everything.
if you subtract one point from another , you get the vector. the vector shows a force that has a direction and a velocity. it is a line through both points .so you place this vector into the "vel:=" value and anything with this vel flies parallel to the line.
the angle is another thing but even with both points :
for an angle you have to get the tangens of an angle first so you take the y coordinates from both points and subtract them and divide it through both subtracted x coordinates.
now you have a value and now take the arcus tangens for a degree value , what is an angle.
			if you subtract one point from another , you get the vector. the vector shows a force that has a direction and a velocity. it is a line through both points .so you place this vector into the "vel:=" value and anything with this vel flies parallel to the line.
the angle is another thing but even with both points :
for an angle you have to get the tangens of an angle first so you take the y coordinates from both points and subtract them and divide it through both subtracted x coordinates.
now you have a value and now take the arcus tangens for a degree value , what is an angle.
yup yup 
yuuuuuuup
yupyupyupyupyupyupyupyupyyyuuuup
hm... signatures...
		yuuuuuuup
yupyupyupyupyupyupyupyupyyyuuuup
hm... signatures...
- hiltropper
 - Posts: 85
 - Joined: Mon Dec 20, 2010 12:02 pm
 - Location: Germany
 
Re: spawn gun aiming
I remembered how i used to make the angle right, its simple and easy, but ive only tried it with boxes not polygons:
running off memory here(from awhile ago) so might be a typo in there, but it looks right
			
		- Code: Select all
 angle=atan(e.normal(0)/e.normal(1))
running off memory here(from awhile ago) so might be a typo in there, but it looks right
- 
				

niffirg1 - Posts: 376
 - Joined: Mon Aug 31, 2009 10:31 pm
 - Location: The Great American South!
 
Re: spawn gun aiming
Well I think I have a solution..
This scene is the RA2lover's response to my original scene that shoots polygons that are bullet shaped. The polygons did not pointed at the right place so RA2lover made this response showing how to make the bullets have the right angle.
Here is it:
			This scene is the RA2lover's response to my original scene that shoots polygons that are bullet shaped. The polygons did not pointed at the right place so RA2lover made this response showing how to make the bullets have the right angle.
Here is it:
- Code: Select all
 angle := 2 * math.atan( - e.normal(1) / ( - e.normal(0) + 1))
Gears are my favorite mechanism. Why do you think I have this username ? 
Make sure to spend some time to see my work http://www.algodoo.com/algobox/profile.php?id=96, just to kill sometime
PS: Gear97™ Is a trademark from me. Any unauthorized use of the term "Gear" for usernames or other naming ideas will be punished.
		Make sure to spend some time to see my work http://www.algodoo.com/algobox/profile.php?id=96, just to kill sometime
PS: Gear97™ Is a trademark from me. Any unauthorized use of the term "Gear" for usernames or other naming ideas will be punished.
- 
				

Gear97 - Posts: 146
 - Joined: Sat Jan 02, 2010 5:34 pm
 - Location: Brazil
 
			10 posts			 • Page 1 of 1		
	Who is online
Users browsing this forum: No registered users and 7 guests

			
			

