How to spawn an object at the same speed and direction

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

How to spawn an object at the same speed and direction

Postby Zapi » Thu Aug 19, 2010 8:07 pm

Is it possible to spawn an object (in this case, a circle) at the same speed and direction as the spawner (a object that a laser hits inside a rocket that i am making)?

I have some code already, but if I use it as a backwards rocket, or a maneuvering rocket, the spawned mass collides with the rocket and can cause problems.

Code: Select all
(e)=>{scene.addcircle({radius := 0.5;pos := e.pos;friction := 0;density := 5;collideSet := 7;heterocollide := true;color := [0.7, 0, 0, 0.6]}) }
Zapi
 
Posts: 6
Joined: Sat Apr 24, 2010 8:40 am

Re: How to spawn an object at the same speed and direction

Postby Matten » Thu Aug 19, 2010 9:43 pm

How does your rocket looks like?
If it's made like most spawning rockets it could be done without scripting.
Cave Johnson wrote:Do you know who I am? I'm the man who's gonna burn your house down! With the lemons! I'm gonna get my engineers to invent a combustible lemon that burns your house down!
User avatar
Matten
 
Posts: 435
Joined: Mon Apr 05, 2010 2:03 pm
Location: The Netherlands

Re: How to spawn an object at the same speed and direction

Postby electronicboy » Thu Aug 19, 2010 10:30 pm

look on algobox and look for the k probe. you should be able to extract info from that to use in there spawn script. no promise though.
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: How to spawn an object at the same speed and direction

Postby Zapi » Thu Aug 19, 2010 11:11 pm

Matten wrote:How does your rocket looks like?
If it's made like most spawning rockets it could be done without scripting.


Well, I use a object in a tunnel and a laser mounted on a rectangle. When the laser hits the object, the object runs the script i have posted to create a ball, moving at zero meters per second (which is the problem; i want the ball to spawn at the same velocity as the rocket). Above the tunnel is a repeller object that pushes the ball away from the rocket. Newton's third law means that because the ball is pushed away (and the rocket is obviously not mounted to the background), the rocket is pushed alittle as well.

I hope this is what you mean
Zapi
 
Posts: 6
Joined: Sat Apr 24, 2010 8:40 am

Re: How to spawn an object at the same speed and direction

Postby Rideg » Thu Aug 19, 2010 11:16 pm

I did a spawner once that wpaned them with the same speed and direction. Can't find it now though...
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: How to spawn an object at the same speed and direction

Postby Kilinich » Fri Aug 20, 2010 10:36 am

Zapi wrote:Is it possible to spawn an object (in this case, a circle) at the same speed and direction as the spawner (a object that a laser hits inside a rocket that i am making)?

I have some code already, but if I use it as a backwards rocket, or a maneuvering rocket, the spawned mass collides with the rocket and can cause problems.

Code: Select all
(e)=>{scene.addcircle({radius := 0.5;pos := e.pos;friction := 0;density := 5;collideSet := 7;heterocollide := true;color := [0.7, 0, 0, 0.6]}) }


No problem
Just save prev pos and calculate speed on every tick.
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: How to spawn an object at the same speed and direction

Postby Zapi » Fri Aug 20, 2010 12:03 pm

Kilinich wrote:
Zapi wrote:No problem
Just save prev pos and calculate speed on every tick.


Do you have code?
Zapi
 
Posts: 6
Joined: Sat Apr 24, 2010 8:40 am

Re: How to spawn an object at the same speed and direction

Postby Kilinich » Fri Aug 20, 2010 1:22 pm

sure.
here example for box (+ laser).
textureMatrix used just for example, can be replaced with global var.

Code: Select all
onHitBylaser = (e) => {
  currentVel := (e.pos - [textureMatrix(0), textureMatrix(1)]) / (sim.time - textureMatrix(2));
  textureMatrix = e.pos ++ [sim.time] ++ [0,0,0,0,0,0];
//  ... you can now use currentVel in spawn script
}

p.s. didn't test, but you get the point ;-)
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: How to spawn an object at the same speed and direction

Postby Zapi » Fri Aug 20, 2010 2:51 pm

actually, that's confusing to me. i need help with implementing it. i tried pasting the code you have me in, but the mass still spawns at zero meters per second.

I just need to get the velocity of the rocket, and spawn the exhaust at the same velocity so that the rocket will work backwards. is there any way to get the velocity of the object that the laser hits?
Zapi
 
Posts: 6
Joined: Sat Apr 24, 2010 8:40 am

Re: How to spawn an object at the same speed and direction

Postby Rideg » Fri Aug 20, 2010 4:13 pm

what does the "++" mean? :O
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: How to spawn an object at the same speed and direction

Postby Zapi » Sat Aug 21, 2010 12:09 pm

i don't know what it means.
Zapi
 
Posts: 6
Joined: Sat Apr 24, 2010 8:40 am

Re: How to spawn an object at the same speed and direction

Postby Nait » Sat Aug 21, 2010 12:32 pm

Zapi wrote:actually, that's confusing to me. i need help with implementing it. i tried pasting the code you have me in, but the mass still spawns at zero meters per second.

I just need to get the velocity of the rocket, and spawn the exhaust at the same velocity so that the rocket will work backwards. is there any way to get the velocity of the object that the laser hits?

Here

Code: Select all
(e)=>{scene.addcircle({ // Your code\\ ; vel:=currentVel}); currentVel := (e.pos - [textureMatrix(0), textureMatrix(1)]) / (sim.time - textureMatrix(2)); textureMatrix = e.pos ++ [sim.time] ++ [0,0,0,0,0,0] }}


Instead currentVel you can use property of spawner, like Friction, or ControllerAcc...

PS
I didn't test it also, if doesn't work, report me ;)
--------
Rideg wrote:what does the "++" mean? :O

This is adding for lists.
Code: Select all
[1,0]++[2,3]=[1,0,2,3]

Hope you understand me :D
User avatar
Nait
 
Posts: 224
Joined: Fri Oct 30, 2009 1:56 am
Location: Eastern Russia, Vladivostok

Re: How to spawn an object at the same speed and direction

Postby Rideg » Sun Aug 22, 2010 8:55 pm

I belive I do. Thank you for the mini-tutorial ;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


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 2 guests