I'm using an 8 directional pixel movement script and it works great but the only problem is that the diagonal movement speed is too fast because when you move diagonally you're essentially moving two directions (down+left, up+right, etc) in the same time. Is there anyway to adjust individual direction's movement speed?
What is the diagonal movement script you're using?
Quote from: modern algebra on April 22, 2010, 01:48:22 PM
What is the diagonal movement script you're using?
f0tz!bearchan's 1.6 script
http://www.mediafire.com/?diymdgjhynn
I really don't know much about scripts. Is there anyway to edit the distance/time of the diagonal movements? Since it's traveling diagonally across the hypotenuse (the longest side of the two right triangles that form the square) it goes to fast since it's essentially covering more distance in the same time, if that makes any sense
I managed to get the movement speed worked out by changing the script from
[spoiler] #-----------------------------------------------------------------------------
# move_lower_left, more pixellike
#-----------------------------------------------------------------------------
def move_lower_left (steps = 32, turn_enabled = true)
self.turn_lower_left if turn_enabled
# passable?
if passable?(@x, @y, 1, steps)
@x -= @max_steps
@y += @max_steps
increase_steps
else
# checks for event activation
check_event_trigger_touch(@x - @max_steps, @y + @max_steps)
# not passable but the character can walk (@maxsteps > 0)
if (@max_steps > 0 and @max_steps < steps)
@x -= @max_steps
@y += @max_steps
increase_steps
end
end
end[/spoiler]
to
[spoiler] #-----------------------------------------------------------------------------
# move_lower_left, more pixellike
#-----------------------------------------------------------------------------
def move_lower_left (steps = 32, turn_enabled = true)
self.turn_lower_left if turn_enabled
# passable?
if passable?(@x, @y, 1, steps)
@x -= 1
@y += 1
increase_steps
else
# checks for event activation
check_event_trigger_touch(@x - @max_steps, @y + @max_steps)
# not passable but the character can walk (@maxsteps > 0)
if (@max_steps > 0 and @max_steps < steps)
@x -= @max_steps
@y += @max_steps
increase_steps
end
end
end[/spoiler]
I did this for all of the diagonal movements and then for the up,down,left, and right movements i changed the x and y steps to 1.4 (to account for the hypotenuse).
This solves the speed problem but now whenever I go to the edge of the screen I get this error:
"Script 'game_character' line 1064: typeerror occured. cannot iterate from Float"
Here's the line of code with line 1064 being underlined
[spoiler]
#-----------------------------------------------------------------------------
# Passable? method
# has been rebuilt for both collision maps and databse passability
#-----------------------------------------------------------------------------
def passable?(x, y, d = 0, self_event = nil)
# returns if coords are not on the map
return false if not valid?(x, y)
# if d is not 2, 4, 6 or 8
case d
when 0
return true
when 1
return (passable?(x, y, 2, self_event) and passable?(x, y, 4, self_event))
when 3
return (passable?(x, y, 2, self_event) and passable?(x, y, 6, self_event))
when 7
return (passable?(x, y, 8, self_event) and passable?(x, y, 4, self_event))
when 9
return (passable?(x, y, 8, self_event) and passable?(x, y, 6, self_event))
else
return false if not [2, 4, 6, 8].include?(d)
end
# loads size
if self_event == nil
x_size = y_size = 2
else
x_size = [self_event.size['x'], 2].max
y_size = [self_event.size['y'], 2].max
end
# checks pixel on collision map / in the database
counter = 0
case d
when 2
fix = y - 1
for i in (x - x_size / 2)..(x + x_size / 2 - 1)
counter += 1 if i%2 == 0 and self.pixel_passable?(i, fix, d, self_event)
end
return counter >= x_size / 2
when 4
fix = (x - x_size / 2)
for i in (y - y_size - 1)..(y - 1)
counter += 1 if i%2 == 0 and self.pixel_passable?(fix, i, d, self_event)
end
return counter >= y_size / 2
when 6
fix = (x + x_size / 2 - 1)
for i in (y - y_size - 1)..(y - 1)
counter += 1 if i%2 == 0 and self.pixel_passable?(fix, i, d, self_event)
end
return counter >= y_size / 2
when 8
fix = (y - y_size - 1)
for i in (x - x_size / 2)..(x + x_size / 2 - 1)
counter += 1 if i%2 == 0 and self.pixel_passable?(i, fix, d, self_event)
end
return counter >= x_size / 2
end
[/spoiler]
So i'm assuming that by changing the x and y modifiers I made this part of the script that deals with passability incompatible. I would assume that i would only have to change some of the numbers to fix this but i'm not sure since i suck at scripts