Problem with Float Point, please help
I want to move the X position by, let's say, 1.5, but it always count it as 1. This is my code:
Repeat while (Joystick) Moved left
Player: Set Pos X to -1.5
Repeat while (Joystick) Moved right
Player: Set Pos X to 1.5
NO Repeat while (Joystick) Moved left
NO Repeat while (Joystick) Moved right
Player: Set Pos X to 0
Always
Player: Set X position to X("Player")+ Pos X ("Player")
Where Pos X is Alternate Value A.
Thanks
Re: Problem with Float Point, please help
This is because the X position of the player is only whole numbers, so when you add +/- 1.5 to it it always rounds the half out.
You need to do it like this:
Start of Frame:
Player: Set alt Pos X to X("Player")
Repeat while (Joystick) Moved left
Player: Set alt Speed X to -1.5
Repeat while (Joystick) Moved right
Player: Set Speed X to 1.5
NO Repeat while (Joystick) Moved left
NO Repeat while (Joystick) Moved right
Player: Set Speed X to 0
Always
Player: Set alt Pos X to alt Pos X("Player") + alt Speed X("Player")
Always
Player: Set X position to alt Pos X("Player")
Re: Problem with Float Point, please help
Excellent, it works. Thank you so much Dynasoft.
Is there a problem if I let the movement like your code? Because some people prefer to make a fast loop in Left/Right Movement to avoid problems, but I don't know if there would be any problem. Thanks
Re: Problem with Float Point, please help
Use fast loop for speed in whole numbers.
use float points for any # speed lower than whole numbers.
Re: Problem with Float Point, please help
The only problem is with stopping movement on collision. If you are moving at over 1px/frame, you can end up stuck slightly in whatever you collide with. You can then use a fast loop to pull out of it if you need it perfect.
If you go faster than your size (e.g. bullets) then you can skip over other objects altogether, which forces you to use a fast loop for the movement to get a good result.
Re: Problem with Float Point, please help
Quote:
Originally Posted by Dynasoft
The only problem is with stopping movement on collision. If you are moving at over 1px/frame, you can end up stuck slightly in whatever you collide with. You can then use a fast loop to pull out of it if you need it perfect.
If you go faster than your size (e.g. bullets) then you can skip over other objects altogether, which forces you to use a fast loop for the movement to get a good result.
Hmm yes, there is problem with that :mad: I didn't noticed because I was making just a plane foreground. So now I have to change everything in fast loops... just when I was happy for making a lot of MegaMan X engine =/
Anybody can help me in converting a piece of code in fast loop? I can post the code if someone help me with that. Thank you so much