Page 1 of 1

spawning a circle with a velocity?

PostPosted: Thu Dec 17, 2009 2:33 pm
by Rideg
hello me again curios as always:P i've been wondering how to "load" a velocity of a spawned circle.

example: When a circle spawns it should be moving with a velocity of 10m/s and a box tells it which angle it should be "velocifyed" at;P

Thank you for helping me learning this:P
//rideg

Re: spawning a circle with a velocity?

PostPosted: Thu Dec 17, 2009 4:04 pm
by standardtoaster
When spawning it use vel := [x, y]. x is how fast the object will move left or right in meters a second. y is how fast the object will move up or down in meters a second.

Re: spawning a circle with a velocity?

PostPosted: Thu Dec 17, 2009 4:42 pm
by Rideg
Thanks but how do you replace "x" and"y" with something like scene.my.angelvelocity?

Re: spawning a circle with a velocity?

PostPosted: Thu Dec 17, 2009 5:12 pm
by standardtoaster
Calculate scene.my.angelvelocity and then in the velocity put [scene.my.angelvelocity(0), scene.my.angelvelocity(1)].

Re: spawning a circle with a velocity?

PostPosted: Thu Dec 17, 2009 6:12 pm
by Rideg
I meant something like vel:=[300 * cos(scene.my.angvelocity), 300 * (scene.my.angvelocity).

Scene.my.angvelocity is the angle of the box that the spawner is attached to and I can't figure it out how to connect the variable to the box.

Re: spawning a circle with a velocity?

PostPosted: Thu Dec 17, 2009 6:44 pm
by standardtoaster
Oh. Thanks for telling me that. To convert the angle of the box into speed you want to spawn you can use e.normal or cosine and sine. vel := e.normal * 300 or vel := [300 * math.cos(scene.my.anglevelocity), 300 * math.sin(scene.my.anglevelocity)]

Re: spawning a circle with a velocity?

PostPosted: Thu Dec 17, 2009 6:46 pm
by Sonic
Are you trying to make a gun with adjustable power?

Re: spawning a circle with a velocity?

PostPosted: Thu Dec 17, 2009 7:10 pm
by Rideg
Could I have an example code please? didn't fully understand..

Re: spawning a circle with a velocity?

PostPosted: Thu Dec 17, 2009 7:22 pm
by standardtoaster
Converting a scalar velocity, a speed with magnitude but no direction such as 15 m/s, requires a bit of knowledge in trigonometry. Looking at your post, I can see that you suggested 300 to be the constant scalar. Assuming you have found the angle, we can now calculate it. I will make a function for this so it will be easy to modify.
Code: Select all
Scene.my.speed=(v, a)=>{[v * math.cos(a), v * math.sin(a)]

v is the velocity that you will use as a constant
a is the angle, in radians, of the gun

Scene.my.speed(15, math.pi/4) will give you [10.606602, 10.606602]

You can use that to spawn a circle with the preset velocity. vel := scene.my.speed(15, scene.my.angle)

Re: spawning a circle with a velocity?

PostPosted: Thu Dec 17, 2009 7:26 pm
by Rideg
ok thanks

Re: spawning a circle with a velocity?

PostPosted: Thu Dec 17, 2009 9:27 pm
by KarateBrot
Btw [a*x, a*y] = a*[x,y]
this can slim down some code. it's not important, i just wanted to mention^^

so for this example:
[v * math.cos(a), v * math.sin(a)] is the same as v * [math.cos(a), math.sin(a)]

Re: spawning a circle with a velocity?

PostPosted: Thu Dec 17, 2009 9:49 pm
by Rideg
I can't get this to work:( maybe I should do smaller stuff, Can't figure it out how it works(yet!).

Re: spawning a circle with a velocity?

PostPosted: Thu Dec 17, 2009 9:54 pm
by standardtoaster
Can you please post what you currently have? It would really help if I knew what I have to work with here.

Re: spawning a circle with a velocity?

PostPosted: Thu Dec 17, 2009 9:58 pm
by Rideg
sure wait some minutes:P

Re: spawning a circle with a velocity?

PostPosted: Thu Dec 17, 2009 10:06 pm
by Rideg
[scene]35064[/scene]
here you go thank you ALOT if you can make a simple code so I can understand this.

Re: spawning a circle with a velocity?

PostPosted: Thu Dec 17, 2009 10:15 pm
by standardtoaster
I will take a look at it in about half an hour.

Re: spawning a circle with a velocity?

PostPosted: Thu Dec 17, 2009 11:12 pm
by standardtoaster
The biggest problem that the scene centers around is this.angle. The easiest fix to this is instead of spawning the circles with vel := [100 * math.cos(scene.my.angle), 100 * math.sin(scene.my.angle)] I would suggest using vel := e.normal * 100.

Re: spawning a circle with a velocity?

PostPosted: Thu Dec 17, 2009 11:22 pm
by Rideg
what does e.normal mean??

Re: spawning a circle with a velocity?

PostPosted: Fri Dec 18, 2009 1:31 am
by KarateBrot
e.normal is the normal of the collision event
http://en.wikipedia.org/wiki/Surface_normal

So you don't need to bother about the angle anymore.

Re: spawning a circle with a velocity?

PostPosted: Sat Dec 19, 2009 2:09 am
by Rideg
but that doesn't give the angle the spawned circle chould be velocifyed at, does it?

Re: spawning a circle with a velocity?

PostPosted: Sat Dec 19, 2009 2:46 pm
by Rideg
Got it now thanks alot for the help! :D

Re: spawning a circle with a velocity?

PostPosted: Sat Dec 19, 2009 3:14 pm
by KarateBrot
e.normal is a vector. the angle is already in it ;)

Re: spawning a circle with a velocity?

PostPosted: Sat Dec 19, 2009 4:16 pm
by Rideg
and then I typed a script: (vel:=100*scene.my.angle) scene.my.angle = e.normal of the event were the laser hits it! thank you :lol: