Be a Supporter!

x < 0 cause strange behavior

  • 264 Views
  • 3 Replies
New Topic Respond to this Topic
nitokov
nitokov
  • Member since: May. 8, 2012
  • Offline.
Forum Stats
Member
Level 05
Programmer
x < 0 cause strange behavior 2013-01-25 18:45:52 Reply

So here is the problem, i am writing some behavior simulator
http://www.newgrounds.com/dump/item/ce2ce8ea15e625adf788e4c7 671a71a6

I have mc pitch with top left reg point, and some players. Players movement are fine until x < 0 then strange thing happen.

if(move_player)
{
_speed += _acc;
if (_speed > _maxspeed)
{
_speed = _maxspeed;
}
					
_angle = Math.atan2(_dy, _dx) * 180 / Math.PI;
		
if (Math.abs(_angle - rotation) > 180)
{
if (_angle > 0 && rotation < 0)
{
rotation -= (360 - _angle + rotation)// / _turning;
}
else if (rotation > 0 && _angle < 0)
						{
							rotation += (360 + _angle - rotation)// / _turning;
						}
					}
					else if (_angle < rotation)
					{
						rotation -= Math.abs(rotation - _angle)// / _turning;
					}
					else
					{
						rotation += Math.abs(_angle - rotation)// / _turning;
						
					}
					
					if (_speed < 0)
					{
						_speed = 0;
					}
_xinc = Math.cos(rotation * Math.PI / 180) * _speed;
			if (rotation < 0)
			{
				_yinc = -_speed + Math.abs(_xinc); //Going upwards.
			}
			else
			{
				_yinc = _speed - Math.abs(_xinc); //Going downwards.
			}
			
			x += _xinc;
			y += _yinc;
}

RangeError: Error #1125: The index 4 is out of range 4.

nitokov
nitokov
  • Member since: May. 8, 2012
  • Offline.
Forum Stats
Member
Level 05
Programmer
Response to x < 0 cause strange behavior 2013-01-25 22:58:16 Reply

Anyone? The problem is that xinc doesn't change but amount of actual movement by x axis does, this is so mystic and annoying as hell


RangeError: Error #1125: The index 4 is out of range 4.

4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Response to x < 0 cause strange behavior 2013-01-26 05:30:37 Reply

You said "strange things happen". That could mean a billion things. You also said when "x < 0" I don't see a variable called "x". Are you referring to dx? Or something else?

You're being awfully cryptic. It's hard to help you when we don't know what it is you're trying to achieve, and what the code is doing now.

Did you try using "trace()" to output values for debugging?

nitokov
nitokov
  • Member since: May. 8, 2012
  • Offline.
Forum Stats
Member
Level 05
Programmer
Response to x < 0 cause strange behavior 2013-01-26 22:33:25 Reply

I changed some code, had rough night, but i manage to sort things out. I didn't mess with movement code but apparently this glitch does not exist anymore


RangeError: Error #1125: The index 4 is out of range 4.