entity:jump_create() works, but entity:jump() does not. The only main different is entity:jump_create() makes the sprite with script and entity:jump() needs a sprite and on_created():
-- Event called when the custom entity is initialized.
function entity:on_created()
entity:jump()
end
-------------------------------------------
--Entity Create Jump Method
-------------------------------------------
function metatable_entity:jump_create(sprite_directory, speed, traversable, set_can_traverse_hero, set_traversable_by_hero, ignore_obstacles, direction8, jump_distance, animation, finish_animation, finish_time, finish_jump_sound, jump_sound, sound_timer, dialog, dialog_activation_distance)
local map = self:get_map()
local hero = map:get_hero()
local game = map:get_game()
local sprite
local quick_movement
--speed default value
if speed == nil then
speed = 40
end
if traversable == nil then
traversable = false
end
--By default the entity cannot traverse the hero
if set_can_traverse_hero == nil then
set_can_traverse_hero = false
end
--By default the hero cannot traverse the entity.
if set_traversable_by_hero == nil then
set_traversable_by_hero = false
end
--By default the entity does not ignore obstacles
if ignore_obstacles == nil then
ignore_obstacles = false
end
if direction8 == nil then
direction8 = 0
end
if jump_distance == nil then
jump_distance = 100
end
--By default the sprite directory is the hero tunic1
if sprite_directory == nil then
sprite_directory = "main_heroes/Eldran"
end
if animation == nil then
animation = "jumping"
end
if finish_animation == nil then
finish_animation = "stopped"
end
if finish_time == nil then
finish_time = 3000
end
if jump_sound == nil then
jump_sound = "jump"
end
if finish_jump_sound == nil then
finish_jump_sound = "jump"
end
if sound_timer == nil then
sound_timer = 500
end
--By default the welcome sign dialog is used.
if dialog == nil then
dialog = "welcome_sign"
end
--dialog_activation_distance default value
if dialog_activation_distance == nil then
dialog_activation_distance = 20
end
function self:on_created()
sprite = self:create_sprite(sprite_directory) -- sprite_directory
self:set_can_traverse("hero", set_can_traverse_hero) -- set_can_traverse_hero
self:set_traversable_by("hero", set_traversable_by_hero) -- set_traversable_by_hero
self:set_drawn_in_y_order(true)
self:set_traversable_by(traversable)
quick_movement = sol.movement.create("jump")
self:get_sprite():set_animation(animation) -- animation
quick_movement:set_ignore_obstacles(ignore_obstacles) -- ignore obstacles
quick_movement:set_direction8(direction8) --direction8
quick_movement:set_distance(jump_distance) -- distance
quick_movement:set_speed(speed) -- speed
quick_movement:start(self)
sol.timer.start(sound_timer, function() --finish_time
sol.audio.play_sound(jump_sound) --finish_animation
end)
end
sol.timer.start(finish_time, function() --finish_time
sol.audio.play_sound(finish_jump_sound)
self:get_sprite():set_animation(finish_animation) --finish_animation
end)
function self:on_interaction()
local distance_check = hero:get_distance(self)
if distance_check <= dialog_activation_distance then -- dialog_activation_distance
if hero:get_direction() == 0 then
self:set_direction(2)
map:get_game():start_dialog(dialog) -- dialog
end
if hero:get_direction() == 1 then
self:set_direction(3)
map:get_game():start_dialog(dialog) -- dialog
end
if hero:get_direction() == 2 then
self:set_direction(0)
map:get_game():start_dialog(dialog) -- dialog
end
if hero:get_direction() == 3 then
self:set_direction(1)
map:get_game():start_dialog(dialog) -- dialog
end
end
end
function self:on_movement_changed()
sprite:set_direction(quick_movement:get_direction4())
end
end
-------------------------------------------
--Entity Jump Method
-------------------------------------------
function metatable_entity:jump(speed, traversable, ignore_obstacles, direction8, jump_distance, animation, finish_animation, finish_time, finish_jump_sound, jump_sound, sound_timer, dialog, dialog_activation_distance)
local map = self:get_map()
local hero = map:get_hero()
local game = map:get_game()
local quick_movement
--speed default value
if speed == nil then
speed = 40
end
if traversable == nil then
traversable = false
end
--By default the entity does not ignore obstacles
if ignore_obstacles == nil then
ignore_obstacles = false
end
if direction8 == nil then
direction8 = 0
end
if jump_distance == nil then
jump_distance = 100
end
if animation == nil then
animation = "jumping"
end
if finish_animation == nil then
finish_animation = "stopped"
end
if finish_time == nil then
finish_time = 3000
end
if jump_sound == nil then
jump_sound = "jump"
end
if finish_jump_sound == nil then
finish_jump_sound = "jump"
end
if sound_timer == nil then
sound_timer = 500
end
--By default the welcome sign dialog is used.
if dialog == nil then
dialog = "welcome_sign"
end
--dialog_activation_distance default value
if dialog_activation_distance == nil then
dialog_activation_distance = 20
end
self:set_drawn_in_y_order(true)
self:set_traversable_by(traversable)
quick_movement = sol.movement.create("jump")
self:get_sprite():set_animation(animation) -- animation
quick_movement:set_ignore_obstacles(ignore_obstacles) -- ignore obstacles
quick_movement:set_direction8(direction8) --direction8
quick_movement:set_distance(jump_distance) -- distance
quick_movement:set_speed(speed) -- speed
quick_movement:start(self)
sol.timer.start(sound_timer, function() --finish_time
sol.audio.play_sound(jump_sound) --finish_animation
end)
sol.timer.start(finish_time, function() --finish_time
sol.audio.play_sound(finish_jump_sound)
self:get_sprite():set_animation(finish_animation) --finish_animation
end)
function self:on_interaction()
local distance_check = hero:get_distance(self)
if distance_check <= dialog_activation_distance then -- dialog_activation_distance
if hero:get_direction() == 0 then
self:set_direction(2)
map:get_game():start_dialog(dialog) -- dialog
end
if hero:get_direction() == 1 then
self:set_direction(3)
map:get_game():start_dialog(dialog) -- dialog
end
if hero:get_direction() == 2 then
self:set_direction(0)
map:get_game():start_dialog(dialog) -- dialog
end
if hero:get_direction() == 3 then
self:set_direction(1)
map:get_game():start_dialog(dialog) -- dialog
end
end
end
function self:on_movement_changed()
self:set_direction(quick_movement:get_direction4())
end
end
The Fix:
--Manual jump direction check
if direction8 == 0 or direction8 == 1 then
if self:get_direction() == 1 then -- up
self:set_direction(0)
end
if self:get_direction() == 2 then -- left
self:set_direction(0)
end
if self:get_direction() == 3 then -- down
self:set_direction(0)
end
if self:get_direction() == 0 then-- right
self:set_direction(0)
end
end
if direction8 == 2 or direction8 == 3 then
if self:get_direction() == 1 then -- up
self:set_direction(1)
end
if self:get_direction() == 2 then -- left
self:set_direction(1)
end
if self:get_direction() == 3 then -- down
self:set_direction(1)
end
if self:get_direction() == 0 then-- right
self:set_direction(1)
end
end
if direction8 == 4 or direction8 == 6 then
if self:get_direction() == 1 then -- up
self:set_direction(2)
end
if self:get_direction() == 2 then -- left
self:set_direction(2)
end
if self:get_direction() == 3 then -- down
self:set_direction(2)
end
if self:get_direction() == 0 then-- right
self:set_direction(2)
end
end
if direction8 == 6 or direction8 == 7 then
if self:get_direction() == 1 then -- up
self:set_direction(3)
end
if self:get_direction() == 2 then -- left
self:set_direction(3)
end
if self:get_direction() == 3 then -- down
self:set_direction(3)
end
if self:get_direction() == 0 then-- right
self:set_direction(3)
end
end