Say we have scene with spring field node at the (0;0) and some node affected by this field.
Weird thing: if we put node at (0;0), it flies away immediately with huge speed; if put at some offset, like (0;10), it moves toward field node, oscillates for some time before stay at (0;0) and then flies away. Is there any way to prevent this?
Turned out this only appears in iOS 8.
Problem lurks in calculation of force multiplier. If we set falloff = 0 or min radius = 0, such behaviour doesn't appear. So setting minRadius to 0 solved the problem. Thanks #0x141E for support.
Upd:
I was wrong - setting minRadius doesn't solve the problem. I didn't noticed that field coordinates displayed as (0;0) in Scene Editor in a fact were non-zero, delta was about 1*10^-4, while node was placed exactly at (0;0). Such quite small initial distance seems to help, but can't say what will happen if node eventually stay at the centre of the field.
For this time solution is to add initial distance and wait for end of iOS 8 support for app.
Related
How do I prevent the player from dying when they fall in the void?
The only way to do it is to lift it up the Y-Axis.
I recommend selecting everything then moving it up an EXACT amount of studs (e.g. 100) Then just change the script and add 100 studs to all the values.
To be safe I would increase it by a lot more studs than you think you will need.
This is the only way I know of and I think is possible,
Hope this helps.
From devforum.roblox.com, executing the following
workspace.FallenPartsDestroyHeight=0/0
from the command bar will set FallenPartsDestroyHeight to nan which appears to disable the automatic destruction of objects based on Y position.
Having an issue with farseer physics im pretty sure the issue is just with this line of code because of the y value. So when i try to move my character when falling he moves left and right normally but his fall slows.
body.LinearVelocity = new Vector2(1,0)
Is there a way to only change the x value of this? Or is there a way to prevent sliding and set a cap on the speed of applyforce() or applylinearimpulse()?
By setting the linear velocity to 1,0 you give the character a horizontal speed of 1 and a vertical speed of 0. So you effectively stop it from falling.
The following code will do what you would expect as it preserves the vertical speed.
body.LinearVelocity = new Vector2(1, body.LinearVelocity.y);
In some (most) cases it is better to apply a force or impulse to the character using body.Apply... this applies a force for a single frame and Farseer will automatically compute the correct velocity. Note that adding the same force or impulse every frame will make the movement speed-up.
The problem is simple: I want to move (and later, be able to rotate) an image. For example, every time i press the right arrow on my keyboard, i want the image to move 0.12 pixels to the right, and every time i press the left arrow key, i want the image to move 0.12 pixels to the left.
Now, I have multiple solutions for this:
1) simply add the incremental value, i.e.:
image.x += 0.12;
this is of course assuming that we're going to the right.
2) i multiplicate the value of a single increment by the times i already went into this particular direction + 1, like this:
var result:Number = 0.12 * (numberOfTimesWentRight+1);
image.x = result;
Both of these approaches work but produce similiar, yet subtly different, results. If we add some kind of button component that simply resets the x and y coordinates of the image, you will see that with the first approach the numbers don't add up correctly.
it goes from .12, .24, .359999, .475 etc.
But with the second approach it works well. (It's pretty obvious as to why though, it seems like += operations with Numbers are not really precise).
Why not use the second approach then? Well, i want to rotate the image as well. This will work for the first attempt, but after that the image will jump around. Why? In the second approach we never took the original position of the image in account. So if the origin-point shifts a bit down or up because you rotated your image, and THEN you try to move the image again: it will move to the same position as if you hadn't rotated before.
Alright, to make this short:
How can i reliably move, scale and rotate images for 1/10 of a pixel?
Short answer: I don't know! You're fighting with floating point math!
Luckily, I have a workaround, if you don't mind.
You store the location (x and y) of the image in a separate variable... at a larger scale. Such as 100x. So 123.45 becomes 12345, and you then divide by 100 to set the attribute that flash uses to display.
Yes, there are limits to number sizes too, but if you're willing to accept some error rate, and the fact that you'll be limited to, I dunno, a million pixels in each direction, you can fit it in a regular int. The only rounding error you will encounter will be a single rounding error when you divide by 100 (or the factor you used). So instead of the compound rounding error which you described (0.12 * 4 = 0.475), you should see things like 0.47999999. Which doesn't matter because it's, well, so small.
To expand on #Pimgd answer a bit, you're probably hitting a floating point error (multiple +='s will exaggerate the error more than one *='s) - Numbers in Flash are 53-bit precision.
There's also another thing to keep in mind, which is probably playing a bigger role with such small movement values; Flash positions all objects using twips, which is roughly about 1/20th of a pixel, or 0.05, so all values are rounded to this. When you say image.x += 0.12, it's actually the equivalent of image.x += 0.10, hence which the different becomes apparent; you're losing 0.02 of a pixel with every move.
You should be able to get around it by moving to another scale, as #Pimgd says, or just storing your position separately - i.e. work from a property _x rather than image.x so you're not losing that precision everytime:
this._x += 0.12;
image.x = this._x;
Hello in a game I'm making using lua in Marmalade Quick,I have run into a problem with the physics.
I have a normal downward y gravity and have some notes that is affected by that.
Now I want to add some objects that "fly" horizontally on the X axis but I can not get it to work.
so one of the notes looks like this:
sky2 = director:createSprite(dw, 40, "textures/tractor.png")
physics:addNode(sky2, {type="dynamic"})
sky2.physics:setGravityScale(0)
my first thought was to
just add the following to an update listener
if(gameplaying == true) then
sky2.x = sky2.x-2.5
unfortunately this does not work after the node has got added physics
then I was looking into using
sky2.physics:applyapplyLinearImpulse or sky2.physics:applyForce
I used it like this
sky2.physics:applyapplyLinearImpulse(-10, 0, -20, 40)
The problem here is that the node then correctly moves along the axis but it is spinnig around (torque effects)..
Is there away to stop this or what am I doing wrong,,
thanks..
Found out that the Marmalade Quick Documentation was wrong, and to not input both a px and a px value but just 0 so sky2.physics:applyapplyLinearImpulse(-10, 0) this will apply the impulse at the centre of mass and make it move straight.
So i have a custom UISlider. It's vertical (i did it with the +270° technic). I have 3 images, respectively for the minimum value, maximum value and for the thumb. Everything seems good but i have problems with the extrema values, as you can observe on the screen capture (even though it's a little dark).
The slider on the left is perfect ! Both end of the sliders show the images perfectly and the cursor (thumb) is perfectly cutting the slider in 2.
The other two sliders on the right shows a similar issue. We can see that, when in extrema value, the cursor is not well located (there shouldn't be any part of the image below or above the middle of the cursor !) Oo
More to that, let's look at the right slider (with minimum value). We can see that image has been cut on the bottom ! Indeed it should be close. It's the same thing for the maximum value, the image looks like it's been cut.
I looked at the bounds of the slider view by touching it at both ends and looking at its coordinates. The slider was defined with a height of 300 but i can perform touches at coordinate 307, or -6 !!! I don't really understand why..
For more information, coordinates form 300 to 310 represents the maximum value i defined and negative coordinates (from 0 to -10) represents the minimum value.
-> So We can notice there's a difference of 10 at both ends.
Please help ! :s