edited April 2015 in ORK Scripting
I'm trying to use a custom camera script and trying to attach the camera to the player. To do this, the script can either use a tag, or I can specify the transform of the prefab etc.

I'm wondering how I can change the player and have the camera change as well. What I mean is, if I have 4 combatants in a real time battle, I want to be able to have the camera move to the combatant I'm currently controlling. How can I do this?

I was thinking that maybe I can attach an invisible prefab to the currently active combatant, and have the camera always attached to this. Is this something that's possible? Is there some other better method?
Post edited by gamingislove on
  • Maybe i didn't understand well... But can't you have just one camera and focus it on the active combatant (i suppose performing events/attacks) while he is doing an action? Custom camera is control is attached to camera itself, not player, it means it doesn't care about which is the player at the moment.
    Perhaps if you tell us what you want to achieve we can give a more detailed answer. :)
  • edited April 2015
    But the camera itself needs to be attached to an object as well. E.g. what object is it looking at and following? If you don't do this, the camera won't follow the player, it will just sit there in space. With the ork camera what you are saying is true, I think Ork attaches its camera to ORK.Game.GetPlayer(), which is the active player, and follows that around. I'm not sure how to do this with a custom camera system. I want to avoid editing its code since i'll probably update it at some point and break stuff, then forget how to fix it :)
    Post edited by Juryiel on
  • Uhm if you need the camera to be attached to the object, you could use component enable for specific situation: you use a default camera and you active these components by events checking the user/combatant/whatever you need. ^^
    I am not good at scripting, neither i ever changed ORK Code, but my camera/object/player scripts work well with ORK custom controls attachment and event system. :)
  • If your script either needs a tag or a transform, you'll either need to set a tag to the player's game object or change the code to get the current player game object.
    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!
  • edited April 2015
    How can i tag the player's game object?

    EDIT: My thought was to add a script to something i the scene (perhaps automatically through ork) that sets the tag. I then told Ork to attach this script to my camera under custom controls.

    I tried something like this:
    using UnityEngine;
    using System.Collections;
    using ORKFramework;

    public class Jury_StartupSetup : MonoBehaviour {

    // Use this for initialization
    void Start () {
    GameObject player = ORK.Game.GetPlayer();
    player.tag = "CameraTarget";
    }

    // Update is called once per frame
    void Update () {
    GameObject player = ORK.Game.GetPlayer();
    player.tag = "CameraTarget";
    }
    }


    So far this did not work. It attaches correctly to the first player but doesn't change. I think the camera itself won't reattach since it's already on something called "CameraTarget". Not sure anyway where to go from here.
    Post edited by Juryiel on
  • edited April 2015
    Got this to work finally. This is how this can be done without editing the asset code for either ORK or the Camera system. I"m using SimpleRpgCamera asset:

    I made a script called Jury_StartupSetup, and had ORK attach this to the camera automatically. My camera is named Main Camera. The camera script has the 'target' variable accept a transform to focus on.

    using UnityEngine;
    using System.Collections;
    using ORKFramework;

    public class Jury_StartupSetup : MonoBehaviour {


    // Use this for initialization
    void Start () {
    GameObject theCamera = GameObject.Find("Main Camera");
    SimpleRpgCamera cameraScript = theCamera.GetComponent<SimpleRpgCamera>();
    cameraScript.target = ORK.Game.GetPlayer().transform;
    }

    // Update is called once per frame
    void Update () {
    GameObject theCamera = GameObject.Find("Main Camera");
    SimpleRpgCamera cameraScript = theCamera.GetComponent<SimpleRpgCamera>();
    cameraScript.target = ORK.Game.GetPlayer().transform;
    }
    }


    I think putting the code in Update() is probably a bad idea though. I would ideally only want it to trigger when there is a player change. Is there some trigger for that?
    Post edited by Juryiel on
  • Yes, there's an event listener available for that. Add the following function to your script:

    public void PlayerChanged(Combatant newPlayer, Combatant oldPlayer)

    Do your camera changes there - a combatant's game object can be accessed like this (check if it's not null before using it):

    newPlayer.GameObject

    Register your function in the Start function of your script:

    ORK.Game.PlayerHandler.Changed += this.PlayerChanged;

    And you should remove the function from the event listener when the script is destroyed:

    void OnDestroy()
    {
    ORK.Game.PlayerHandler.Changed -= this.PlayerChanged;
    }
    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!
  • Great thanks, that worked well :)
Sign In or Register to comment.