edited December 2015 in ORK Scripting
using UnityEngine;
using System.Collections;

public class Character_Movement : MonoBehaviour
{
public float maxSpeed = 10f;
public float gravity = -1f;
//bool facingRight = true;

Animator anim;

// Use this for initialization
void Start ()
{
anim = GetComponent<Animator> ();
}

// Update is called once per frame
void FixedUpdate ()
{
float moveH = Input.GetAxis("Horizontal");
float moveV = Input.GetAxis("Vertical");

Vector3 movement = new Vector3 (moveH, 0.0f, moveV);
Vector3 grav = new Vector3 (0.0f, gravity, 0.0f);

anim.SetFloat ("speed", Mathf.Abs (moveH)); //set parameter speed pada animator
anim.SetFloat ("Vspeed", Mathf.Abs (moveV));

rigidbody.velocity = movement * maxSpeed;
rigidbody.AddForce(grav*maxSpeed);

//horizontal_movement
//problem is right here
if (moveH > 0)
{
right (moveH);
}
else if (moveH < 0)
{
left ();
}

//vertical_movement
if (moveV > 0)
{
up ();
}
else if (moveV < 0)
{
down ();
}
//print (moveH);

}
//the problem is right here
public float right(float R_num)
{
float ret;
ret = R_num/R_num;
anim.SetBool ("toRight", true);
anim.SetBool ("toLeft", false);
anim.SetBool ("toUp", false);
anim.SetBool ("toDown", false);
return ret;
}

void left()
{
anim.SetBool ("toRight", false);
anim.SetBool ("toLeft", true);
anim.SetBool ("toUp", false);
anim.SetBool ("toDown", false);
}

void up()
{
anim.SetBool ("toRight", false);
anim.SetBool ("toLeft", false);
anim.SetBool ("toUp", true);
anim.SetBool ("toDown", false);
}

void down()
{
anim.SetBool ("toRight", false);
anim.SetBool ("toLeft", false);
anim.SetBool ("toUp", false);
anim.SetBool ("toDown", true);
}


}


From this script above, im trying to use Check function from node editor...

the idea was to call the function to do an action everytime the player faces right (attack defend etc)

but the problem is, whenever i tried to use the 'right' function, unity returns a warning about the method's not found

my guess is there's something wrong in the code...

and i'm sorry I can't be more specific... since this code is for learning and not a project
Post edited by gamingislove on
  • Now, I'm a terrible coder, but I don't see the function that you're trying to call in the event. There's no 'right' function in there, if I'm reading it correctly.
    Tactics RPG Grid Battle System for ORK
    ---------------------------------------
    Personal Twitter: https://twitter.com/AMO_Crate
    I make RFI! https://twitter.com/NootboxGames
  • I've changed rigidbody line and tested no error.
    This is the code.


    using UnityEngine;
    using System.Collections;

    public class Character_Movement : MonoBehaviour
    {
    public float maxSpeed = 10f;
    public float gravity = -1f;
    //bool facingRight = true;

    Animator anim;

    // Use this for initialization
    void Start()
    {
    this.anim = this.GetComponent<Animator>();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
    float moveH = Input.GetAxis("Horizontal");
    float moveV = Input.GetAxis("Vertical");

    Vector3 movement = new Vector3(moveH, 0.0f, moveV);
    Vector3 grav = new Vector3(0.0f, this.gravity, 0.0f);

    this.anim.SetFloat("speed", Mathf.Abs(moveH)); //set parameter speed pada animator
    this.anim.SetFloat("Vspeed", Mathf.Abs(moveV));


    //This is the line I modified
    this.GetComponent<Rigidbody>().velocity = movement * this.maxSpeed;
    this.GetComponent<Rigidbody>().AddForce(grav * this.maxSpeed);


    //horizontal_movement
    //problem is right here
    if (moveH > 0)
    {
    this.right(moveH);
    }
    else if (moveH < 0)
    {
    this.left();
    }

    //vertical_movement
    if (moveV > 0)
    {
    this.up();
    }
    else if (moveV < 0)
    {
    this.down();
    }
    //print (moveH);

    }
    //the problem is right here
    public float right(float R_num)
    {
    float ret;
    ret = R_num / R_num;
    this.anim.SetBool("toRight", true);
    this.anim.SetBool("toLeft", false);
    this.anim.SetBool("toUp", false);
    this.anim.SetBool("toDown", false);
    return ret;
    }

    void left()
    {
    this.anim.SetBool("toRight", false);
    this.anim.SetBool("toLeft", true);
    this.anim.SetBool("toUp", false);
    this.anim.SetBool("toDown", false);
    }

    void up()
    {
    this.anim.SetBool("toRight", false);
    this.anim.SetBool("toLeft", false);
    this.anim.SetBool("toUp", true);
    this.anim.SetBool("toDown", false);
    }

    void down()
    {
    this.anim.SetBool("toRight", false);
    this.anim.SetBool("toLeft", false);
    this.anim.SetBool("toUp", false);
    this.anim.SetBool("toDown", true);
    }


    }
    Playmaker and Behavior Designer Integration for ORK Famework
    http://www.gamekakkak.com
  • edited December 2015
    Kirb..

    your comment might help me... really

    I've been confused about what a function is and i just half following a basic tutorial.

    can you give me an example of a function?

    this might help me in the future...
    Post edited by Kuruwa_Yoshiko on
  • edited December 2015
    A function is code that does something. It performs a task. When you define a function you can then use it without having to rewrite the block of code.

    For example, in your code, void left () is a function as is void up () and void down().

    You can then use those functions to do that stuff each one contains by just writing -
    void up();

    A function that starts off void returns no value-- it's still useful because it does something.


    Your right function is not named like the others because it returns a value.

    Your right function is ---

    Public float right (float R_num)

    The value it returns is float R_num but I don't see where that is used in your code.



    Is the name of the function you're referring to in the node editor exactly the same as the name of your right function above?

    Edit:

    And it looks like the function you're calling up top is right(moveH);

    But the name of your defined function is right(float R_num).

    I don't see any connection between moveH and R_num.

    What does R_num do and how does it relate to moveH? Other than their both being floats?

    About functions returning values--

    http://stackoverflow.com/questions/15237649/what-exactly-does-a-return-statement-do-in-c


    Post edited by Catacomber on
  • edited December 2015
    Your defined function is public float right(float R_num).
    public is its visibility
    float is its type
    right is its name
    float R_num is its parameters

    Disregard what I posted here before---I'm not sure your problem is the code at all but how you set it up to be checked in the editor.



    Post edited by Catacomber on
  • - im currently trying to process this slowly as my english is kinda wacky XD

    yes, my "right" function is different because i'm currently trying to make it into a function that return R_num, so yeah the function i tried to call was this one

    public float right(float R_num)

    the plan was using it with check function on node editor (sorry for the late explanation)
    image

    the purpose is to make my 2D sprite animate the "right side" attack animation (sorry for this too) if the return value is 1 (R_num/R_num)

    as for how my R_num and move_H is unrelated... actually i am following this basic tutorial here :
    https://unity3d.com/learn/tutorials/modules/beginner/scripting/variables-and-functions

    In this page it said that the variable myInt is "inserted" into the function as int number and then returned ... so I'm kinda following that

    as for your suggestion... i didn't do it yet, but i'll try...

    oh and one more thing...

    the Component Name is the name of the script
    then what should i put in function name? i tried right but it gave me the method not found warning



  • edited December 2015
    In the editor---In the drop down menu for return type, did you choose float? The name of your function is right.

    You might need to add a parameter in the editor. Not at my computer right now-- if you click on Function Name in the editor and click on Add Parameter in the editor you should get some tip on what to put there.
    Post edited by Catacomber on
  • edited December 2015
    Will try to duplicate it and see what happens but I don't use 2d graphics. About the name of your function--also called method---

    Public float right (float R_num)

    public is its visibility -default is private to preserve not being tampered with by other code--but by making it public in Unity you create a box you can see in the editor that allows changing the values in the code and sometimes this is very useful like the speed of the player.

    float is its type

    right --its name--what you were asking

    (float R_num)--its parameters--they can be temporary so you don't have to define them--I just found that out. : )

    I think your problem might be more how you set this up in the editor. But again not sure as I haven't tried it.

    Is your float set to 1.0 in the editor? When you choose the dropdown of float?

    Post edited by Catacomber on
  • So, you want to call the right function of your Character_Movement component in ORK's Check Function step?

    - set Component Name to Character_Movement
    - disable the Is Static option
    - select the game object you want to use this on (e.g. the user actor)
    - set Function Name to right
    - set Return Value Type to Float
    - set Float Value to the value it should check for
    - click on Add Parameter (since your function requires a float parameter)
    - set the Parameter Type to Float and Float Value to the value you want to use

    If you need a more complex check, you can use the Function To Variable step to store the result into a game variable and do more complex checks on that variable.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • That is a really nice tutorial on calling a function. : )
  • Heck, that suddenly works XDDDDD

    thanks for that

    now, i actually have more problems..

    but I'll try to get around it (until i give up and probably post it here XD)

    and happy new year XD
Sign In or Register to comment.