Speed Locking?

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

Speed Locking?

Postby mold999 » Tue Jan 22, 2013 10:45 pm

Is there any way to lock an objects speed to a specific direction?

Meaning, if I have an arrow:

-->

And I want it to go only in the direction it is pointing, is there any way to do this?
I would like it to work even if I rotate the arrow, like this:

/\
|

And it will start to move upwards.

Thanks,

--mold999
Phundementalism?

Ain't nobody got
thyme fo dat.
User avatar
mold999
 
Posts: 225
Joined: Sun Jan 02, 2011 1:35 am
Location: [176436, 3763234]

Re: Speed Locking?

Postby Kilinich » Wed Jan 23, 2013 9:37 am

No easy way to do...
But you can try use one of my "wheels" for that:
Rating: rated 6
Filesize: 19.11 kB
Comments: 7
Ratings: 3
download
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: Speed Locking?

Postby mold999 » Wed Jan 23, 2013 11:28 pm

Could you explain a little more about the scene?

Like the n and vn variables in the wheels, and the clamp(). Also the n and s variables in the thrusters.

Thanks,
Phundementalism?

Ain't nobody got
thyme fo dat.
User avatar
mold999
 
Posts: 225
Joined: Sun Jan 02, 2011 1:35 am
Location: [176436, 3763234]

Re: Speed Locking?

Postby Kilinich » Thu Jan 24, 2013 12:30 am

mold999 wrote:Could you explain a little more about the scene?
Like the n and vn variables in the wheels, and the clamp(). Also the n and s variables in the thrusters.


Code for wheel:
Code: Select all
v := entity.vel;
n := [ - math.sin(entity.angle), math.cos(entity.angle)];
vn := ((v(0) * n(0) + v(1) * n(1)));
entity.vel = entity.vel - n * clamp(vn,  - entity._maxForce, entity._maxForce) * entity._airForceMult;


n - normal direction vector of wheel with length = 1
vn - velocity projection to that normal, means how fast wheel moving in "side" direction
clamp is a build-in function declared in config just a limits for value (x, min, max)

Same for thruster but instead of normal I use forward direction vector. "s" means velocity projection to forward direction, or how fast car movig forward (backward is negative) removing "side" part of velocity.
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: Speed Locking?

Postby mold999 » Fri Jan 25, 2013 5:02 pm

I was thinking...

Can't I just set the velocity of the arrow to

[Math.sin(angle), Math.cos(angle)]

And multiply by a factor to increase the speed?

I tried it, but it wouldn't work. Is there something I'm doing wrong?
Phundementalism?

Ain't nobody got
thyme fo dat.
User avatar
mold999
 
Posts: 225
Joined: Sun Jan 02, 2011 1:35 am
Location: [176436, 3763234]

Re: Speed Locking?

Postby Kilinich » Fri Jan 25, 2013 5:18 pm

My script stops wheel from moving sideways. Did you get it?
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: Speed Locking?

Postby mold999 » Fri Jan 25, 2013 7:05 pm

Yes, I got it. :)

But, why doesn't [Math.sin(angle), Math.cos(angle)] work? Shouldn't that just give the x and y speeds?
Phundementalism?

Ain't nobody got
thyme fo dat.
User avatar
mold999
 
Posts: 225
Joined: Sun Jan 02, 2011 1:35 am
Location: [176436, 3763234]

Re: Speed Locking?

Postby Kilinich » Fri Jan 25, 2013 8:53 pm

mold999 wrote:Yes, I got it. :)

But, why doesn't [Math.sin(angle), Math.cos(angle)] work? Shouldn't that just give the x and y speeds?

Result is vector pointing to direction of geom's "front" ;-) not speed
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


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 5 guests