Spawning bullet at e.angle?

About advanced scenes, and the Thyme scripting language used in Algodoo.

Spawning bullet at e.angle?

Postby Dare » Wed Mar 16, 2011 9:23 am

Well I want to spawn a bullet, that is rectangular in shape.

How do I spawn the bullet so it is at the same angle of the laser/box that is spawning it?

I'm sure there is some simple code.
ImageImage
TC42 wrote:Dare, you are creepy.

Official Algobox Admin! Please PM me if you have any issues regarding Algobox.
User avatar
Dare
 
Posts: 833
Joined: Sat Nov 21, 2009 4:27 pm
Location: Sydney, Australia

Re: Spawning bullet at e.angle?

Postby Kilinich » Wed Mar 16, 2011 11:23 am

Search normal to angle function it thyme script forum
viewtopic.php?f=13&t=2900&start=0&hilit=normal+angle
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Spawning bullet at e.angle?

Postby Rideg » Wed Mar 16, 2011 1:20 pm

Code: Select all
angle := math.atan(e.normal(1) / (e.normal(0) + 1)) * 2
Image
make sure to check out my work.
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden

Re: Spawning bullet at e.angle?

Postby Kilinich » Wed Mar 16, 2011 3:26 pm

Rideg wrote:
Code: Select all
angle := math.atan(e.normal(1) / (e.normal(0) + 1)) * 2

aha, try this if e.normal = [-1,0] :P
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Spawning bullet at e.angle?

Postby Rideg » Thu Mar 17, 2011 7:42 pm

Can't try for a few days what's the result?
Image
make sure to check out my work.
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden

Re: Spawning bullet at e.angle?

Postby Someone Else » Wed Mar 23, 2011 3:52 am

Very complicated, but I used it in my S-Unit 2.0. It works quite well.

Code: Select all
{math.asin(e.normal(0)) > 0} ? {controllerAcc = math.acos(e.normal(0))} : {controllerAcc = (-1) * (math.acos(e.normal(1)))}

Should work (typed from memory), and stores the angle in controllerAcc. 0 is up (talking about normals here), clockwise is positive, counterclockwise is negative. Exactly ideal for air-friction stabilizers.
Matthias Wandel is epic, in my humble opinion.
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.
User avatar
Someone Else
 
Posts: 1147
Joined: Sun Nov 21, 2010 10:53 pm
Location: The Milky Way Galaxy

Re: Spawning bullet at e.angle?

Postby KarateBrot » Tue Apr 05, 2011 3:08 pm

Rideg wrote:Can't try for a few days what's the result?

the result will be a undefined result because of dividing by zero^^
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Spawning bullet at e.angle?

Postby Rideg » Tue Apr 05, 2011 8:51 pm

Kilinich wrote:
Rideg wrote:
Code: Select all
angle := math.atan(e.normal(1) / (e.normal(0) + 1)) * 2

aha, try this if e.normal = [-1,0] :P

I just tested it. Strangely enough, I've been using that method for 6 months perhaps and never come across any issues with it.
Image
make sure to check out my work.
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden

Re: Spawning bullet at e.angle?

Postby Someone Else » Wed Apr 06, 2011 3:42 am

The only problem I can see with my code is that when the normal points down, it may give [math.pi] or [- math.pi]. But that should be easy to get around.
Matthias Wandel is epic, in my humble opinion.
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.
User avatar
Someone Else
 
Posts: 1147
Joined: Sun Nov 21, 2010 10:53 pm
Location: The Milky Way Galaxy


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 7 guests