How to spawn an object at the same speed and direction
13 posts • Page 1 of 1
How to spawn an object at the same speed and direction
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.
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
How does your rocket looks like?
If it's made like most spawning rockets it could be done without scripting.
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!
-

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

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
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...
-

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
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
sure.
here example for box (+ laser).
textureMatrix used just for example, can be replaced with global var.
p.s. didn't test, but you get the point
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...
-

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
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?
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
what does the "++" mean? :O
-

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
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
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
-

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

Rideg - Posts: 948
- Joined: Tue Dec 15, 2009 5:17 pm
- Location: Östersund, Sweden
13 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 3 guests




