I have a gameobject(with planet sprite and collision object with sphere shape) and another gameobject(it should be a cursor). My plan is to make movement of planet that way:
1)User clicks on planet(selects it)
2)User clicks on place it should be moved to
3)Planet moves to that place
I have no problem with 2 and 3 steps(I read tutorials and so on), but I have difficultes in 1 step.
I am trying to make it with collisions, but I don’t understand how it works, I haven’t found any examples.
This might make things easier for you. If you would like to write it on your own - you will need to convert action screen coordinates to your world coordinates - it depends then on what camera you are using - is it a game with one screen or can you move around your view around the world (space in your case I guess ) . If you are using Rendercam or Defold Orhtographic Camera for this - then they have conversion functions already
But I am afraid this is not the thing I actually need.
I have this script for cursor right now:
function init(self)
msg.post(".", "acquire_input_focus")
self.collided_id = nil -- id of gameobject which the cursor collided with
self.dragged_pos = nil -- The position of the dragged_id game object
self.owned = false
end
function on_input(self, action_id, action)
if action_id == hash("touch") then
msg.post("#collisionobject", "enable")
local position = vmath.vector3(action.x, action.y, 0)
go.set_position(position, ".")
end
end
function on_message(self, message_id, message, sender)
-- check for the message
if message_id == hash("collision_response") then
-- take action
print("I collided with", message.other_id)
end
end
--[[
Don’t care about unused variables. This script controls cursor, moves its GO when detects touch on screen. But, when I click on another GO with Collision Object, it doesn’t work!
Sometimes a GO with a collision object doesn’t move because of the type of collision object (some of them are immovable). Try changing the type of collision object to see if that helps.