1 (edited by DolceVita 2017-02-10 18:26:47)

Topic: Move 3dMarker depending on camera look

Hi,

Frankly to say, I am new in Unity3d (hovewer skilled in C#).
I have a 3dmap with buildings etc. I placed a 3dmarker (which is basicly a default unity3d thirdPersonController).

I have the script to control my 3dMarker:

    private void FixedUpdate()
    {
        OnlineMaps api = OnlineMaps.instance;

        float h = CrossPlatformInputManager.GetAxis("Horizontal");
        float v = CrossPlatformInputManager.GetAxis("Vertical");

       
        m_CamForward = Vector3.Scale(m_Cam.forward, new Vector3(1, 0, 1)).normalized;
        var position = v * m_CamForward + h * m_Cam.right;
        if (position.magnitude > 1f) position.Normalize();
        //probably I need to do something here to change h and v depending on the camera angle

        px += h / 100000;
        py += v / 100000;
        api.SetPosition(px, py);
}

So right now my player move in 4 directions. However, if I try to change camera look (with mouse right click), I want my character  move forward concidering new "north".

Could you please give a clue how to do this? Thank you.

Re: Move 3dMarker depending on camera look

Hello.

The modified script is attached.

1. Move «ThirdPersonUserControl» script outside of «Standard Assets» or move «Online Maps» folder into «Standard Assets».
2. Wrap «ThirdPersonController» in a new empty GameObject, and create a prefab from the outer GameObject.
3. Use the new prefab for 3D marker.

Post's attachments

Attachment icon ThirdPersonUserControl.cs 3.59 kb, 318 downloads since 2017-02-13 

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Move 3dMarker depending on camera look

Alex Vertax wrote:

Hello.

The modified script is attached.

1. Move «ThirdPersonUserControl» script outside of «Standard Assets» or move «Online Maps» folder into «Standard Assets».
2. Wrap «ThirdPersonController» in a new empty GameObject, and create a prefab from the outer GameObject.
3. Use the new prefab for 3D marker.

Thanks, Alex! Works perfectly

...
  api.GetTilePosition(out px, out py);
...

 var cameraLook = Vector3.Scale(m_Cam.forward, new Vector3(-1, 0, -1)).normalized;
                m_Move = h * cameraLook + v * m_Cam.right;
                px -= m_Move.x * moveScale;
                py += m_Move.z * moveScale;
                double lng, lat;
                api.projection.TileToCoordinates(px, py, api.zoom, out lng, out lat);
                api.SetPosition(lng, lat);