Why is object moving passed the walls?
Using the floating point movement as the base. I noticed if the speed of the object is too fast, the object goes 'passed' the walls. Shouldn't it still hit the wall, no matter what the current speed of the object is?
Here's the mfa of what I'm talking about.
Re: Why is object moving passed the walls?
Of course not.
Imagine this scenario:
A 1 pixel big object moves at 5 frames per frame.
Its starting X position is 0.
Theres a 1px thin vertical wall at X position 12.
Frame 0: Object's X is 0.
Frame 1: Object's X is 5.
Frame 2: Object's X is 10.
Frame 3: Object's X is 15.
Since the object never overlaps the wall, there's no colision. It kind of "jumps over" it.
To fix this, you could use fast loops.
Run a loop X times every frame, X being the X velocity.
Every loop, you move the object either one pixel to the left or to the right (only the MMf position, not the float one), depending on the velocity. If the object overlaps a wall (put the loop condition above), stop the loop and update the float X position. Same goes for Y.
Re: Why is object moving passed the walls?
Well I checked DavidN's fastloop tutorial. But that doesn't help me with this method of movement. His fastloop tutorial gives an absolute value and relies on actual X position of object. While mine pretty much relies on the floats, or alterable values for the position, making sure the floats remains the position of the object.
I tried adding fastloops in the mix, but it just seemed to mess up, no matter what I do. X_X
EDIT: Okay, I added fastloops, but it doesn't 'feel' the same as using the events without them.
What is abs()? Does that mean absolute value or something? Wouldn't that effect the floats to become absolute value? In other words, round up or down?
Is there an opposite for abs()? One of these things that still makes use of floats? Because when I use 'abs(Value A("Active")) Times' for the fast loop, it seems to round it. I still want to use the floats.
Apparently there is a difference between
'Start Loop "move-x" abs(Value A("Active")) Times' - (Where value A is named Velocity X)
and
'Start loop "move-x" 1 times'
Re: Why is object moving passed the walls?
Of course there will be a difference between the 2. Unless your velocity is only 1 then it will be different.
Abs() makes a number always positive.
So for example abs(-19485) will turn into 19485.
As far as I know you can have decimals with abs, it doesnt do any rounding at all, merely makes sure you never have a negative number.
Ceil() and Floor() are used to round values.
Re: Why is object moving passed the walls?
But when I use fast loops, and abs() function for the number of times to do the fast loop, it seems like it's rounding the velocity or position anyway. When the display says that Velocity X is still over 0 (ex. 0.56789), the object does NOT move at all. It only moves when the velocity is 1, or over 1.
When I remove the fast loop function, the object moves even at 0.56789, like I want (with the exception that the object still passes through the walls at full speed). But it does NOT move at Velocity x at 0.56789 when I use fast loop? This is weird. Explanation? X_X
EDIT: I updated the MFA on the link at top. I included two frames in it. One without the fast loops, and one with the fast loops. It seems like it makes the object move faster when I use fast loop? That is not right. They are supposed to move at the same speed. X_X
Re: Why is object moving passed the walls?
Well you cant run a loop 0.56789 times, thats why.
Abs() doesnt do any rounding. Fastloops can only be run in full digits, so it will round the decimal values (sounds like its rounding them down).
You may need to use Ceil() in your case to make sure that values are rounde up (if thats what u want)
I think you are a bit confused as to how this works. You want to call a fastloop the number of pixels that are going to be moved each step. On each loop you move the object 1 pixel in the direction and test for a collision.
If no collision exists you keep going. If a collision then you stop the loop as this means you hit a wall.
Thats the basic concept of it all.
Re: Why is object moving passed the walls?
So, fast loops can't use decimals, or floats? o_O
The deceleration & position will always vary depending on the current # the velocity and position shows. Using fast loops makes the object move faster than I want.
I want to be able to move the same speed like in the first frame, but still use fast loops to prevent the object from passing through the walls using the current speed & position. X_X
Re: Why is object moving passed the walls?
You can't loop for 0,645 times. Fastloop perform in steps. A step is a solid number from 0 to whatever you choose. I think you misunderstood the concept behind it. Please check out the tutorial at: http://www.clickteam.com/website/usa/img/uploads/tutorials/download/fastlooptutorial.zip
It explains how to use the loops and even comes with an example on how to push objects out of walls if they overlap. That is the only thing you need to add to your code and it will work for sure.
Re: Why is object moving passed the walls?
But my point still remains. My Velocity and Position uses floats/decimal points. And fast loops doesn't handle numbers in floats/decimal points. The fast loop tutorial won't help much if the object moves passed the walls, since it doesn't technically overlap them. Not to mention it doesn't show an example of using alterable values with decimal points/floats under fast loops. So my code would still make the object move passed the walls due to an oversight in using floating point movement. X_X
Re: Why is object moving passed the walls?
An object can only have a location that's an integer number of pixels - the actual position of the object in your movement is an approximation to the nearest whole number to your X and Y position variables (check the position of it in the debugger). The number of times that a fastloop is run is an approximation of the velocity, in the same way - you can't run a fastloop a fraction of the time. (And you need to move the object a pixel at a time during the fastloop up to (velocity) times, not moving it by that velocity each time the fastloop is run).
My platform tutorial deals with floating point velocities, but just uses the actual X and Y positions for the position. I think it would be possible to adapt it so that you kept track of the floating point positions as well outside the concept of looping, but I don't know if that would give you a noticeable advantage, X, underscore, X.
Re: Why is object moving passed the walls?
In other words, it's impossible to make an object have precise/exact acceleration & deceleration under static movement due to fast loops only able to do whole numbers.
I used fast loops in my static platform that uses floats/decimal points, but at the point where the character stands sliding on the ice, he slides weird then how I want him to slide. For example, he instantly stops sliding instead of a true deceleration. The only time it looks right is if i DON'T use fast loops. X_X