Hello everyone,
I have been playing around with defold for a while and was struck with how to create a look at mouse function which top down shooters use. someone pls help me out?
I have an example of a top down shooter with mouse look-at: https://github.com/britzl/publicexamples/tree/master/examples/rotate_and_move
Thanks for the nice project but how can it be extended to get a dynamic camera?
P.S. while implementing this camera type, when I move the mouse, the ground starts to rotate instead of the player.How to solve that problem?
If you are attaching the camera to the player then it will rotate with the player. Attaching the camera to another game object and moving that object in sync with the player will solve your problem. An even better solution is to use defold-orthographic or RenderCam extensions from the asset portal.
Got it. Thanks a lot for your valuable help
Hello again.
I revived This old topic because when mmaking my game for LD42 i faced the same problem again, the only difference was that earlier I had made it with the zombies examples, but got when trying with defold orthographic. Can someone plz help me implement it with orthographic.plz
Thanks in advance.
I can upgrade the Defold-Orthographic sample to do this. Would you mind opening a ticket on github for this?
The general idea is that you convert mouse screen coordinates to world coordinates and compare these to world coordinates of player and rotate based on this.
I would have been glad to and will definitely do, but the game I am developing for ld 42 uses this, so any possible workaround suggestions for now?
Perhaps too late but this is what you want:
local cursor_world = camera.screen_to_world(go.get_id("camera"), vmath.vector3(action.x, action.y, 0))
local player_world = go.get_world_position()
local angle = math.atan2(player_world.x - cursor_world.x, cursor_world.y - player_world.y)
local rotation = vmath.quat_rotation_z(angle)
go.set_rotation(rotation)
It’s not so. For a few days, I decided to work on the LD project and complete it 'cause I think it will be better and more fun to play. So, it will definitely be useful.
this sounds interesting.
Can you pls guide me how it’s done as I am using github for the first time, so no exp in its usage.
BTW: Many, many thanks for helping me out…
Every GitHub project tracks the code and any changes to it. You also have one page per project showing tagged/named releases of the code. Then you have one page per project showing Pull Requests (ie contributions from others). Finally there’s also one page per project showing Issues, which works as a bug/feature tracker. Anyone with a Github account can submit issues to that list. Select the Issues page for the project and click New/Create and then fill in the form.
Added…
And fixed: https://github.com/britzl/defold-orthographic/issues/6 (actually it was already added to the example before you posted the issue)