You should use a positive density for dynamic bodies.
Make a scrolling platform [solved]
Bugs, Requests, and FeedbackOh yes, great ! Thanks !
Now it works better. In my game the plateform moves in loop but it stops (after one movement) in Testbed…
What do I need to modificate to choose from where to where it goes ?
Here is the new nearly-working Testbed example : http://pastie.org/1051728
Thanks 🙂
Now it works better. In my game the plateform moves in loop but it stops (after one movement) in Testbed…
What do I need to modificate to choose from where to where it goes ?
Here is the new nearly-working Testbed example : http://pastie.org/1051728
Thanks 🙂
Sheeft wrote:
Oh yes, great ! Thanks !
Now it works better. In my game the plateform moves in loop but it stops (after one movement) in Testbed…
What do I need to modificate to choose from where to where it goes ?
Here is the new nearly-working Testbed example : http://pastie.org/1051728
Thanks 🙂
Now it works better. In my game the plateform moves in loop but it stops (after one movement) in Testbed…
What do I need to modificate to choose from where to where it goes ?
Here is the new nearly-working Testbed example : http://pastie.org/1051728
Thanks 🙂
If you have it looping correctly in your game, can't you just replicate that behavior in your testbed app?
Also, just to clarify, did you get everything working the way you wanted, or are there still problems? And if there are still problems, what are they exactly?
The problem is that, if it loops in my game, I cannot control from where to where it goes…
I tried with the limits, but it seems that they are useless when I loop it with the following each frame (I had forgotten it in the tesbed and it also works nearly the same) :
I want it to move from xi to xf… (which are in pixels but I didn't forget to convert it in box2D units) and I cannot see how…
Thanks in advance ! 😀
I tried with the limits, but it seems that they are useless when I loop it with the following each frame (I had forgotten it in the tesbed and it also works nearly the same) :
Code:
static int i = 0;
m_joint->SetMotorSpeed(cosf(100.5f * i));
i++;
m_joint->SetMotorSpeed(cosf(100.5f * i));
i++;
I want it to move from xi to xf… (which are in pixels but I didn't forget to convert it in box2D units) and I cannot see how…
Thanks in advance ! 😀
Well, that code looks a little suspect to me. Even assuming that you're running the update at a fixed frequency and therefore the time step can be ignored, given that cosf() works with radians, that code is basically going to produce a more or less random sequence of motor speeds that is unlikely to produce the effect that you're after.
I guess the first thing I'd try would be to use a small value (< 1) rather than 100.5, and then to multiply the result by some constant in order to get a motor force of the desired magnitude.
That said, I've never actually tried to move a platform using a motor as you're doing, so I'm really just guessing here. Note that another option would be to make the platform a kinematic object and move it by setting the velocity manually.
I guess the first thing I'd try would be to use a small value (< 1) rather than 100.5, and then to multiply the result by some constant in order to get a motor force of the desired magnitude.
That said, I've never actually tried to move a platform using a motor as you're doing, so I'm really just guessing here. Note that another option would be to make the platform a kinematic object and move it by setting the velocity manually.
Well, I put that force because it didn't move with less…
I'm trying with a lot of values but it seems that any other than it (more or less) are not moving really (just vibrating)…
edit : It seems that it works better with 10.5 but I don't understand why these values…
I'm trying with a lot of values but it seems that any other than it (more or less) are not moving really (just vibrating)…
edit : It seems that it works better with 10.5 but I don't understand why these values…
I probably can't offer much more in the way of help without sitting down with the code myself, but I'll go ahead and comment on the code you're asking about:
How's your trig? Are you familiar with the 'cosine' function?
In short, the cosine and sine functions produce a smooth, oscillating wave when presented with a linearly increasing or decreasing input value.
The multiplier for 'i' in the above code (100.5 in this case) will determine how fast the motor speed oscillates between its two opposite extremes. Since cosf() works with radians and the update rate for your program is probably fairly high, I would think a small value (significantly less than 1) would be needed here to prevent rapid oscillation. (Note that it would probably be better to use the actual elapsed time rather than an integer here.)
The 'magnitude' value will determine the maximum magnitude of the force that is applied to the platform; in other words, the applied force will be in the range [-magnitude, magnitude].
Code:
m_joint->SetMotorSpeed(cosf(100.5f * i) * magnitude);
How's your trig? Are you familiar with the 'cosine' function?
In short, the cosine and sine functions produce a smooth, oscillating wave when presented with a linearly increasing or decreasing input value.
The multiplier for 'i' in the above code (100.5 in this case) will determine how fast the motor speed oscillates between its two opposite extremes. Since cosf() works with radians and the update rate for your program is probably fairly high, I would think a small value (significantly less than 1) would be needed here to prevent rapid oscillation. (Note that it would probably be better to use the actual elapsed time rather than an integer here.)
The 'magnitude' value will determine the maximum magnitude of the force that is applied to the platform; in other words, the applied force will be in the range [-magnitude, magnitude].
Yes I know that… [in fact, I hadn't understood that cosf() was the same as cos() but for floats… Shame on me]
Thanks ^^
It is better like that - and more logical - but I think, that the best would be to set manually the force…
Can't I check if the body has reached the limit ?
Thanks ^^
It is better like that - and more logical - but I think, that the best would be to set manually the force…
Can't I check if the body has reached the limit ?
Quote:
Yes I know that…
Oh, sorry. (I took 'I don't understand why these values' to mean you didn't understand what that bit of code was doing.)
Quote:
It is better like that - and more logical - but I think, that the best would be to set manually the force…
Can't I check if the body has reached the limit ?
Can't I check if the body has reached the limit ?
If by 'reach the limit' you mean reach the left- or right-most allowable position, then sure, you can just check the corresponding coordinate directly.
If that's not what you mean, perhaps you could clarify.
I just edited to add that I misunderstood cosf because of the f >_<
Well, that's what I mean.
But wouldn't it work with isAwake or with the velocity ? (because, if i don't use that cosine thing to set the motor force, the plateform stops when it reached one of the sides -- so doesn't the velocity or speed come to zero ? Or doesn't the body sleep then ?)
Thanks a lot ! 😀
EDIT : I think I get it !
With the following code it now works as I always wanted !
It's really great !
Thanks a lot for your help !
Well, that's what I mean.
But wouldn't it work with isAwake or with the velocity ? (because, if i don't use that cosine thing to set the motor force, the plateform stops when it reached one of the sides -- so doesn't the velocity or speed come to zero ? Or doesn't the body sleep then ?)
Thanks a lot ! 😀
EDIT : I think I get it !
With the following code it now works as I always wanted !
Code:
if(!m_body->IsAwake()) m_joint->SetMotorSpeed(-m_joint->GetMotorSpeed());
It's really great !
Thanks a lot for your help !
Original thread: https://box2d.org/forum/viewtopic.php?t=5251