spawning a circle with a velocity?

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

spawning a circle with a velocity?

Postby Rideg » Thu Dec 17, 2009 2:33 pm

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
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 a circle with a velocity?

Postby standardtoaster » Thu Dec 17, 2009 4:04 pm

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.
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: spawning a circle with a velocity?

Postby Rideg » Thu Dec 17, 2009 4:42 pm

Thanks but how do you replace "x" and"y" with something like scene.my.angelvelocity?
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 a circle with a velocity?

Postby standardtoaster » Thu Dec 17, 2009 5:12 pm

Calculate scene.my.angelvelocity and then in the velocity put [scene.my.angelvelocity(0), scene.my.angelvelocity(1)].
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: spawning a circle with a velocity?

Postby Rideg » Thu Dec 17, 2009 6:12 pm

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.
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 a circle with a velocity?

Postby standardtoaster » Thu Dec 17, 2009 6:44 pm

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)]
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: spawning a circle with a velocity?

Postby Sonic » Thu Dec 17, 2009 6:46 pm

Are you trying to make a gun with adjustable power?
I do stuff and break things. You know how it is.
Image
User avatar
Sonic
 
Posts: 1467
Joined: Tue Sep 01, 2009 6:18 pm
Location: America!!!

Re: spawning a circle with a velocity?

Postby Rideg » Thu Dec 17, 2009 7:10 pm

Could I have an example code please? didn't fully understand..
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 a circle with a velocity?

Postby standardtoaster » Thu Dec 17, 2009 7:22 pm

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)
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: spawning a circle with a velocity?

Postby Rideg » Thu Dec 17, 2009 7:26 pm

ok 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: spawning a circle with a velocity?

Postby KarateBrot » Thu Dec 17, 2009 9:27 pm

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)]
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: spawning a circle with a velocity?

Postby Rideg » Thu Dec 17, 2009 9:49 pm

I can't get this to work:( maybe I should do smaller stuff, Can't figure it out how it works(yet!).
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 a circle with a velocity?

Postby standardtoaster » Thu Dec 17, 2009 9:54 pm

Can you please post what you currently have? It would really help if I knew what I have to work with here.
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: spawning a circle with a velocity?

Postby Rideg » Thu Dec 17, 2009 9:58 pm

sure wait some minutes:P
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 a circle with a velocity?

Postby Rideg » Thu Dec 17, 2009 10:06 pm

[scene]35064[/scene]
here you go thank you ALOT if you can make a simple code so I can understand this.
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 a circle with a velocity?

Postby standardtoaster » Thu Dec 17, 2009 10:15 pm

I will take a look at it in about half an hour.
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: spawning a circle with a velocity?

Postby standardtoaster » Thu Dec 17, 2009 11:12 pm

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.
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: spawning a circle with a velocity?

Postby Rideg » Thu Dec 17, 2009 11:22 pm

what does e.normal mean??
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 a circle with a velocity?

Postby KarateBrot » Fri Dec 18, 2009 1:31 am

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.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: spawning a circle with a velocity?

Postby Rideg » Sat Dec 19, 2009 2:09 am

but that doesn't give the angle the spawned circle chould be velocifyed at, does 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 a circle with a velocity?

Postby Rideg » Sat Dec 19, 2009 2:46 pm

Got it now thanks alot for the help! :D
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 a circle with a velocity?

Postby KarateBrot » Sat Dec 19, 2009 3:14 pm

e.normal is a vector. the angle is already in it ;)
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: spawning a circle with a velocity?

Postby Rideg » Sat Dec 19, 2009 4:16 pm

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:
Image
make sure to check out my work.
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 1 guest

cron