Rotating the normal?

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

Rotating the normal?

Postby Rideg » Tue Oct 05, 2010 9:45 pm

Hello I'm making a "gun" and I've got the "fire" spawner wich spawns a bullet and launches it towards the target.

Now, the spawner has a laser that's triggering it and it's pointed from the right to the spawner.
How can I make the shells to have a velocity that's pointing down? Consider that the gun is rotatable so the "down" vector isn't always down if you have aimed upwards, it wont be pointed vertically. I'm using the right laser triggering to make the bullets go with a velocity * the normal so I can't use that.

Thank you for taking your time reading this
-Johan
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: Rotating the normal?

Postby Nait » Wed Oct 06, 2010 5:09 am

As I know
Code: Select all
normal = [cos, sin]

So try to go this way
Code: Select all
math.atan(e.normal(1)/e.normal(0)) // angle
math.atan(e.normal(1)/e.normal(0))-1.571 // 1,571 rad = 90 degree
// So in the end we have
vel:=[math.cos(math.atan(e.normal(1)/e.normal(0))-1.571), math.sin(math.atan(e.normal(1)/e.normal(0))-1.571)]


It works! I have check)
___________

PS
Instead -1.571 You can place number in radians or formula
Code: Select all
(A/180*Math.Pi)
// A - number in degrees

So there is the same as
Code: Select all
vel:=[math.cos(math.atan(e.normal(1)/e.normal(0))-(90/180*Math.Pi)), math.sin(math.atan(e.normal(1)/e.normal(0))-(90/180*Math.Pi))]

___________

PPS
More correct code is
Code: Select all
vel:=e.normal(0)>0?{[math.cos(math.atan(e.normal(1)/e.normal(0))-1.571), math.sin(math.atan(e.normal(1)/e.normal(0))-1.571)]}:{[math.cos(math.atan(e.normal(1)/e.normal(0))-1.571), math.sin(math.atan(e.normal(1)/e.normal(0))-1.571)]*(-1)}

___________

PPPS
Rating: rated 5
Filesize: 27.27 kB
Comments: 0
Ratings: 1
download
Last edited by Nait on Thu Oct 07, 2010 2:21 am, edited 1 time in total.
User avatar
Nait
 
Posts: 224
Joined: Fri Oct 30, 2009 1:56 am
Location: Eastern Russia, Vladivostok

Re: Rotating the normal?

Postby Rideg » Wed Oct 06, 2010 8:28 pm

Thank you :) Best answer I've got to any question. I think. Biggest thanks ;)
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: Rotating the normal?

Postby Nait » Thu Oct 07, 2010 2:22 am

I'm not very expired in scripts, but if I know something, I will be glad to share ;)
User avatar
Nait
 
Posts: 224
Joined: Fri Oct 30, 2009 1:56 am
Location: Eastern Russia, Vladivostok


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 11 guests