spawning a circle with a velocity?
23 posts • Page 1 of 1
spawning a circle with a velocity?
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
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
make sure to check out my work.
-
Rideg - Posts: 948
- Joined: Tue Dec 15, 2009 5:17 pm
- Location: Östersund, Sweden
Re: spawning a circle with a velocity?
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.
-
standardtoaster - Posts: 606
- Joined: Mon Aug 31, 2009 7:57 pm
Re: spawning a circle with a velocity?
Thanks but how do you replace "x" and"y" with something like scene.my.angelvelocity?
make sure to check out my work.
-
Rideg - Posts: 948
- Joined: Tue Dec 15, 2009 5:17 pm
- Location: Östersund, Sweden
Re: spawning a circle with a velocity?
Calculate scene.my.angelvelocity and then in the velocity put [scene.my.angelvelocity(0), scene.my.angelvelocity(1)].
-
standardtoaster - Posts: 606
- Joined: Mon Aug 31, 2009 7:57 pm
Re: spawning a circle with a velocity?
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.
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.
make sure to check out my work.
-
Rideg - Posts: 948
- Joined: Tue Dec 15, 2009 5:17 pm
- Location: Östersund, Sweden
Re: spawning a circle with a velocity?
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)]
-
standardtoaster - Posts: 606
- Joined: Mon Aug 31, 2009 7:57 pm
Re: spawning a circle with a velocity?
Are you trying to make a gun with adjustable power?
-
Sonic - Posts: 1467
- Joined: Tue Sep 01, 2009 6:18 pm
- Location: America!!!
Re: spawning a circle with a velocity?
Could I have an example code please? didn't fully understand..
make sure to check out my work.
-
Rideg - Posts: 948
- Joined: Tue Dec 15, 2009 5:17 pm
- Location: Östersund, Sweden
Re: spawning a circle with a velocity?
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.
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)
- 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)
-
standardtoaster - Posts: 606
- Joined: Mon Aug 31, 2009 7:57 pm
Re: spawning a circle with a velocity?
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)]
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)]
-
KarateBrot - Posts: 825
- Joined: Mon Aug 31, 2009 7:32 pm
- Location: Germany
Re: spawning a circle with a velocity?
I can't get this to work:( maybe I should do smaller stuff, Can't figure it out how it works(yet!).
make sure to check out my work.
-
Rideg - Posts: 948
- Joined: Tue Dec 15, 2009 5:17 pm
- Location: Östersund, Sweden
Re: spawning a circle with a velocity?
Can you please post what you currently have? It would really help if I knew what I have to work with here.
-
standardtoaster - Posts: 606
- Joined: Mon Aug 31, 2009 7:57 pm
Re: spawning a circle with a velocity?
[scene]35064[/scene]
here you go thank you ALOT if you can make a simple code so I can understand this.
here you go thank you ALOT if you can make a simple code so I can understand this.
make sure to check out my work.
-
Rideg - Posts: 948
- Joined: Tue Dec 15, 2009 5:17 pm
- Location: Östersund, Sweden
Re: spawning a circle with a velocity?
I will take a look at it in about half an hour.
-
standardtoaster - Posts: 606
- Joined: Mon Aug 31, 2009 7:57 pm
Re: spawning a circle with a velocity?
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.
-
standardtoaster - Posts: 606
- Joined: Mon Aug 31, 2009 7:57 pm
Re: spawning a circle with a velocity?
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.
http://en.wikipedia.org/wiki/Surface_normal
So you don't need to bother about the angle anymore.
-
KarateBrot - Posts: 825
- Joined: Mon Aug 31, 2009 7:32 pm
- Location: Germany
Re: spawning a circle with a velocity?
but that doesn't give the angle the spawned circle chould be velocifyed at, does it?
make sure to check out my work.
-
Rideg - Posts: 948
- Joined: Tue Dec 15, 2009 5:17 pm
- Location: Östersund, Sweden
Re: spawning a circle with a velocity?
Got it now thanks alot for the help!
make sure to check out my work.
-
Rideg - Posts: 948
- Joined: Tue Dec 15, 2009 5:17 pm
- Location: Östersund, Sweden
Re: spawning a circle with a velocity?
e.normal is a vector. the angle is already in it
-
KarateBrot - Posts: 825
- Joined: Mon Aug 31, 2009 7:32 pm
- Location: Germany
Re: spawning a circle with a velocity?
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
make sure to check out my work.
-
Rideg - Posts: 948
- Joined: Tue Dec 15, 2009 5:17 pm
- Location: Östersund, Sweden
23 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 19 guests