Problem when animate (SOLVED)

Hello sorry making many questions from previous I done I change the code which works the animation starts but not moving code is this

thanks

if sofo_pos.x < playerPos.x then
sofo_pos.x = sofo_pos.x +1*dt
go.set_position(sofo_pos)
sofo_anim = hash(“sofoklis_right”)

sofo_pos is position of enemy which I want go right and starts animate the right animation but not moving also to say frame in animation is 5 fps and the images is 3. but doesn’t walk probably bec need other amount multiply perhaps. thanks

Hard to tell what is wrong based on what you posted. Here’s an example with sprite animations and movement: https://github.com/britzl/publicexamples/tree/master/examples/play_animation

something else enemy to move normaly what collision must has? I have to him kinematic thanks

Also this animation is of enemy not of player… player moves but enemy no I have in update the code
if you want I can make all paste. thanks

go.property("coin", 1500)
--go.property("speed", 50)
function init(self)	
	timer.delay(5, false, build_sofoklis_R)	
		
	--self.came_message = "nothing"
	self.sofo_moving = true
	--self.sofo_move = vmath.vector3()
	--self.sofo_dir = vmath.vector3()
	self.sofo_current_anim = nil
	--self.sofo_speed = 50
	--self.sofo_correction = vmath.vector3()
end

function build_sofoklis_R(self, handle, time_elapsed)
	my_coin = coin
	--my_speed = speed
	local sofo_R=factory.create(msg.url("#sofoklis_R"),nil,nil,{ coin = my_coin },0.7)
	self.url_sofo_R = msg.url(sofo_R)
	-- how I put second property?
	
end

function final(self)
	-- Add finalization code here
	-- Remove this function if not needed
end

function update(self, dt)
	local playerPos = go.get_position("/player")
	local sofo_anim = hash("sofoklis_idle_right")
	if ((playerPos.y > 255 and playerPos.y < 257) and (playerPos.x > 171 and playerPos.x < 292)) then
		--msg.post("/sofoklis_Right#coin_sofoklis_R", "plat_mykinai")
		print("hello")
		self.sofo_moving = false
		local sofo_pos = go.get_position()

		-- animate sofoklis

			

		if sofo_pos.x < playerPos.x then
			sofo_pos.x = sofo_pos.x +1*dt
			go.set_position(sofo_pos)
			sofo_anim = hash("sofoklis_right")
		elseif sofo_pos.x > playerPos.x then 
			sofo_pos.x = sofo_pos.x -1*dt
			go.set_position(sofo_pos)
			sofo_anim = hash("sofoklis_left")
		end
		
		if sofo_anim ~= self.sofo_current_anim then
			self.url_sofo_R.fragment = "sprite"
			msg.post(self.url_sofo_R, "play_animation", { id = sofo_anim } )
			self.sofo_current_anim = sofo_anim
		end
	
		-- done animating
	end 
	
	if self.sofo_moving == false and (playerPos.y < 255 or playerPos.y > 257) then
		sofo_anim = hash("sofoklis_idle_right")	
		if sofo_anim ~= self.sofo_current_anim then
			self.url_sofo_R.fragment = "sprite"
			msg.post(self.url_sofo_R, "play_animation", { id = sofo_anim } )
			self.sofo_current_anim = sofo_anim
		end
	end	
end

function on_message(self, message_id, message, sender)
	--if message_id == hash("plat_mykinai") then
	--	print("I receive")
		
	--	self.sofo_moving = true		
end



function on_input(self, action_id, action)
	-- Add input-handling code here
	-- Remove this function if not needed
end

function on_reload(self)
	-- Add reload-handling code here
	-- Remove this function if not needed
end

I don’t see any obvious problems. You need to try and debug the code yourself. You can add print() calls to figure out what happens and when. And you can use the debugger to step through the code.

ok thanks I saw move legs of animation but stay same place. Collision I have kinematic. thanks

You are moving only a single pixel per second (1 * dt). Perhaps it is moving, but slowly?

don’t know saws playing the animation but seems like not change place the player moves but enemy not but don’t know why. I will try change the values and see. thanks

Hello again, after 4 days trying I done another test I done an object with same sprite no collision this time I done the object directly in main.collection. And works same code same collision. The other object which not working is of factory and probably not working because not take correct values of pos of object because me I cannot give. Probably I put wrong urls cant understand or sth I done wrong when create the factory. So if you want close the subject even if didn’t make it with the start code but with an individual object. For example a question I may have if you can please someone say the go.get_position() needs certain value of the factory? Thanks

Ok I put again some if and animation and again does not move but I think I will find now the reason. thanks

Now works with

sofo_pos.x = sofo_pos.x+1

and don’t work with

sofo_pos.x = sofo_pos.x+1*dt

I will become crazy … thanks

This means that you will move 1 pixel every frame.

This means 1 pixel every second

The game usually updates 60 frames per second so what you really want is this:

sofo_pos.x = sofo_pos.x+60*dt

When you multiply by dt (delta time) you need to specify distance as pixels per second. So 60*dt means move 60 pixels per second. 200*dt means 200 pixels per second, and so on.

Ok thanks for the info and be well.

I did not get what you said. So you made an animation but it does not move?. Or you made one code for an animation which is okay but the code does not work because you have some error in your code?. What kind of animation is this by the way?.

What should I code if I want to mode 2 pixel every frame and can you please kindly describe what which animation will be the smoothest the one which moves 1 pixel every frame or the one with movement of 2 pixel every second. I am a beginner and since you have given some code demonstrations I think you know a lot about animations.

Look I made an animation for a factory object… that was not moving with dt in it… and maybe with error.
After I made an animation with object which that time I saw without dt was moving, my problem is I want move in low speed like 1 pixel. Also I took the script new one and made a object new through factory again and now does not work like before!!! But this I think is because of wrong msg.url which right now I try to fix. I found in other post of forum from britzl say about print(msg.url()) sth that helps a lot. But me as beginner didn’t know before search of 3 days. Thanks

Oh! I am glad that you found help here and got rid of your problem. Best of luck.