Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - guidez

Pages: [1]
1
Support / Re: Rotate object on Z-axis to face current mouse position
« on: August 06, 2013, 04:27:51 pm »
It looks like the issue was that I wasn't subtracting the mouse position from the gameObject's position, which led to that earlier interesting result. You are the third person to have corrected me, so thank you! Everything seems to be working now.

http://answers.unity3d.com/questions/508685/rotate-object-on-z-axis-to-face-current-mouse-posi.html

2
Support / Rotate object on Z-axis to face current mouse position
« on: August 06, 2013, 04:09:49 am »
I've been at this for a few hours now, thinking it would be nice and simple, but guess not!

All that I want to do is rotate an object along it's Z-axis towards the mouse cursor.

I found some code (see the Rotation part of the full code below) that rotates the object as long as it stays close to the center. This object moves around though, and apparently the farther away the object moves from the center of the scene (0,0 x/y coords), the slower the rotation effect! I want the rotation to always stay constant (IE; instantaneous at this point), but can't for the life of me figure out how to translate the position of the mouse on the screen into the facing rotation Z-axis of the object!

Code: [Select]
using UnityEngine;
using System.Collections;

public class Object_Controller : MonoBehaviour {

    //Public Vars
    public Camera camera;
    public float speed;

    //Private Vars
    private Vector3 mousePosition;
    private Vector3 direction;
    private float distanceFromObject;

    void FixedUpdate() {

        if (Input.GetButton("Fire2")){

            //Grab the current mouse position on the screen
            mousePosition = camera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y, Input.mousePosition.z));

            //Rotates toward the mouse
            rigidbody.rotation = Quaternion.Euler(0, 0, Mathf.Atan2(mousePosition.y, mousePosition.x) * Mathf.Rad2Deg - 90);

            //Judge the distance from the object and the mouse
            distanceFromObject = (Input.mousePosition - camera.WorldToScreenPoint(transform.position)).magnitude;

            //Move towards the mouse
            direction = (mousePosition - transform.position).normalized;
            rigidbody.AddForce(direction * speed * distanceFromObject * Time.deltaTime);

        }//End Move Towards If Case

    }//End Fire3 If case
}
}

3
Support / Guide - Importing a Spine Animation into TK2D
« on: June 28, 2013, 11:30:53 pm »
I have a habit of making guides, hence the name!

http://www.youtube.com/watch?v=dnQbS9ap-i8

4
Support / Re: Sprite Distortion
« on: June 28, 2013, 07:51:25 pm »
It's fricken' night and day! Wow! Thank you so much!

So what constitutes a "harsh" edge? I mean, the circular head is perfectly a circle, but that counts as a harsh edge? Not an artist or real animator here, just fyi. I am assuming that mipmaps are somewhat cpu/gpu intensive, but it almost seems I'd have to enable it for almost everything, correct?

5
Support / Sprite Distortion
« on: June 28, 2013, 07:33:14 pm »
How come my sprite comes out like this?



The sprite texture is a good size and quality, and thus I lower the Ortho and then scale it down some more afterwards as it's simply too large. In the process of scaling it, the image gets worse and worse! My intended export is iPhone, so how do I retain quality as things get scaled down? The default clouds look lovely scaled up or down, so I am just a bit confused here. (total newb btw)

6
Support / Re: check on animation
« on: June 27, 2013, 08:33:30 pm »
See if animation is playing: http://answers.unity3d.com/questions/14599/check-if-a-spesific-animation-is-playing.html

If you just want to make sure "theAnim" is not null, then:

Code: [Select]
if(theAnim){
     anim.Play(theAnim);
}else{
     anim.Play("dummySprite");
}

It's the same as saying

Code: [Select]
if(theAnim != null){
     anim.Play(theAnim);
}else{
     anim.Play("dummySprite");
}

7
Support / Basic Button
« on: June 27, 2013, 08:31:00 pm »
For someone that is still pretty newbish with not only Unity, but with C# as well, I found it very hard to understand the concept of incorporating a Basic Button and having it do something OTHER then play an audioclip. The documentation on this was very lacking. After finally "getting" it today, I think the biggest factor to the confusion was the example of listening to events in "Understanding UI System and Building your Own Components" (http://www.unikronsoftware.com/2dtoolkit/docs/2.00/ui/system.html)

Code: [Select]
void OnEnable()
{
    uiItem.OnDown += ButtonDown;
    uiItem.OnClickUIItem += Clicked;
}

void ButtonDown()
{
    Debug.Log("Button Down");
}

void Clicked(tk2dUIItem clickedUIItem)
{
    Debug.Log("Clicked:" + clickedUIItem);
}

//Also remember if you are adding event listeners to events you need to also remove them:
void OnDisable()
{
    uiItem.OnDown -= ButtonDown;
    uiItem.OnClickUIItem -= Clicked;
}

If you copy/paste the code as-is, you get the following error: error CS0103: The name `uiItem' does not exist in the current context. The example is not clear that you need to have the class extend (if that's the right terminology) tk2dUIBaseItemControl, like:

Code: [Select]
public class MyCScript: tk2dUIBaseItemControl {


    public GameObject lureObject;

    void OnEnable()
    {
uiItem.OnClick += specialMove;
    }

    void OnDisable()
    {
uiItem.OnClick -= specialMove;
    }

    private void specialMove()
    {
        Debug.Log ("Yep");
    }

}

This might seem simple and easy to debug, but for someone just starting out it was extremely frustrating. Everything else so far with 2D toolkit has been great so far though and I feel it's one of the best investments I've made so far.

Pages: [1]