How to transform arbitrary point from local coordinate system of one game object to local space of another? Also, how to transform point from local space to world space and vice versa?
Using vmath API, of course.
Hmm, I guess you’d use go.get_position and go.get_world_position of the two objects to translate the point.
Going from screen to world space is more complex and requires information about the projection of your render script.
This is not what I was asking for.
Simple example (all numbers are random, 2D):
Imagine that we have two objects in global (world) space.
go1 with position (120, 100) and rotation 30 deg.
go2 with position (-40, 60) and rotation -30 deg.
Take arbitrary point in coordinate space of go1 with position (70, 50).
Global (world) coordinates for that point will be (155.622, 178.301)
Coordinates in go2 space for that point will be (110.263, 200.263)
The question is the same: How to transform arbitrary point from local coordinate system of one game object to local coordinate system of another game object?
In other engines this is just one function call, for example:
let position_in_go2_local_space = go2.convert(point, from: go1)
or somethig like that.
How to do that in Defold?
Ah, I see. There’s no go.translate() or anything like that. You’d need to do all of the calculations yourself. There is however something similar when you change parent of a game object at run-time. The set_parent
message takes a keep_world_transform
argument that can make the game object maintain it’s world position even after changing parent.