Adam's Lair Forum

game development and casual madness
It is currently 2019/09/17, 15:38

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: 2013/12/18, 22:44 
Newbie
Newbie

Joined: 2013/11/29, 15:40
Posts: 4
Role: Hobbyist
https://mega.co.nz/#!RBhllS6Q!Wk_y-Wi4k ... 447IzlFRUk

There is my test-learn project. I have one ship facing mouse, and another smaller, has it's coordinates. But it works wrong. Please, show me my mistake.

Thanksfuly, Alex.


Top
 Profile  
 
PostPosted: 2013/12/19, 00:40 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2073
Location: Germany
Role: Professional
The following is a minimal example that should do what you want to achieve. There is no other source code involved and I didn't modify any of your Resources or the Scene:

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Duality;
using Duality.Components.Physics;

using OpenTK;
using OpenTK.Input;
using Duality.Resources;
using Duality.Components;

namespace YourFirstProject
{
    [Serializable]
    [RequiredComponent(typeof(RigidBody))]
    public class Player : Component, ICmpUpdatable
    {
        void ICmpUpdatable.OnUpdate()
        {
         Transform transform = this.GameObj.Transform;

            Vector3 mouseSpacePos = Scene.Current.FindComponent<Camera>().GetSpaceCoord(DualityApp.Mouse.Pos);
         float targetAngle = MathF.Angle(
            transform.Pos.X,
            transform.Pos.Y,
            mouseSpacePos.X,
            mouseSpacePos.Y);

            transform.Angle = targetAngle;
        }
    }

    [Serializable]
    [RequiredComponent(typeof(Transform))]
    public class Cursor : Component, ICmpUpdatable
    {
        void ICmpUpdatable.OnUpdate()
        {
            this.GameObj.Transform.Pos = Scene.Current.FindComponent<Camera>().GetSpaceCoord(DualityApp.Mouse.Pos);
        }
    }
}


You might get an error when running the game with this, since your Scene contains a Func object, which doesn't exist anymore in my version. Don't worry though - it will go away once you save your Scene the next time.

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group