Are you the publisher? Claim or contact us about this channel


Embed this content in your HTML

Search

Report adult content:

click to rate:

Account: (login)

More Channels


Showcase


Channel Catalog


Channel Description:

The latest questions for the topic "independent"

(Page 1) | 2 | 3 | .... | 5 | newer

    0 0

    hi, i was wondering how to make my second camera, that shows interface controls in the top-right corner of the screen, resolution independent.

    i have these values set in the inspector:

    Normalized Viewport Rect: X:0.8 Y:0.0 Width:1 Height:1

    but when i start the player and make game screen bigger, it messes up the view of the second camera. how to make it consistent?


    0 0

    I'm trying to set resolution independence by setting my GUI.matrix via the following code:

    private float nativeHorizontal = 800.0f;
    private float nativeVertical = 600.0f;
    
    void Start() {
        // set resolution independence
        GUI.matrix = Matrix4x4.TRS( Vector3.zero, Quaternion.identity, new Vector3(1.0f*Screen.width / nativeHorizontal, 1.0f*Screen.height / nativeVertical, 1.0f));
    }
    

    Weird thing is, I get the following runtime error:

    InvalidOperationException: Operation is not valid due to the current state of the object System.Collections.Stack.Peek ()

    I've tried searching for Answers (pardon the pun), but I can't find anything. I don't understand how there could be a "stack" error when call the TRS function. Can anybody enlighten me on this?

    Thanks,

    Dendro


    0 0
  • 11/26/10--13:19: Need Help With My GAME!
  • I'm trying to build a 'tower defence' type game, and the game works fine with one turret. But when I have duplicate turrets dotted around the map, the turrets freak out.

    Watch My YouTube Video:http://www.youtube.com/watch?v=6xCRZZiu9pU

    Basically, what happens is when you select a turret, you have the ability to upgrade the firing range, and change many variables. But when I duplicate the turret, the variables get all mixed up (I'm guessing because they are static, as I need to share them).

    And of course, duplicating turrets is important as the user will eventually be able to drag on turrets from a GUI - thus duplicating a prefab (I would imagine).

    How can I go about making each turret variables unique to them selves? I really need this folks! Below are my script if you want to get an idea how things are laid out:

    ClickObject: (script that picks up the mouse click - attached to parent)

    #pragma strict
    
    var clicked : boolean = false;
    var hit : RaycastHit;
    static var ClickedOn : boolean = false;
    
    function Update() {
        if(Input.GetMouseButtonDown(0) &&
           collider.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hit, Mathf.Infinity)) {
            clicked = !clicked;
            if(tag == "Select") tag = "Unselect";
            else tag = "Select";
            //Debug.Log("clicked" + (clicked? "" : " off"));
        }
    ClickedOn = clicked;
    }

    Control: (variables that controls the turrets state - attached to child)

    static var Play = false;
    static var Radius : int = 10;
    static var ModerniseLevel : int = 1;
    static var ModernisePlay : boolean = false;
    static var DisplayCamera : boolean = true;
    static var TurretClicked : boolean = true;
    var TurretCam : Camera;
    
    function Start () {
        TurretCam.enabled = true;       
    }
    
    
    function Update () {
    
        //TurretClicked = ClickObject.ClickedOn;
        collider.radius = Radius;
        //TurretClicked = ClickObject.ClickedOn;
        print(TurretClicked);
    
        if(ModerniseLevel == 2 && ModernisePlay == true){
            animation["SpawnMissile"].speed = 0.5;
            animation.wrapMode = WrapMode.Once;
            animation.Play("SpawnMissile");
            ModernisePlay = false;
        }
    }

    RadiusTexture: (positions sphere around turret according to radius - attached to same child)

    var RadiusObject : Transform;
    var RadiusSphere : Transform;
    private var CurrentSize : float;
    
    private var ScaleX = 3.1; //2
    private var ScaleY = 0; //0
    private var ScaleZ = 3.4; //2.3
    
    private var ScaleXDiv : float = 0;
    private var ScaleYDiv : float = 0;
    private var ScaleZDiv : float = 0;
    
    private var ScaleXNew : float = 0;
    private var ScaleZNew : float = 0;
    
    private var Clicked = false;
    var MouseOverClicked = false;
    
    var Texture = true;
    
    function Update () 
    {
        if(ClickObject.ClickedOn == true)
        {
            LeftMenu.TurnOn = true;
            if(Texture == true)
            {
                CurrentSize = collider.radius;
    
                ScaleXDiv = (ScaleX * CurrentSize);
                ScaleXNew = ScaleXDiv / 10;
    
                ScaleZDiv = (ScaleZ * CurrentSize);
                ScaleZNew = ScaleZDiv / 10;
    
                RadiusObject.transform.localScale = Vector3(ScaleXNew,ScaleY,ScaleZNew);
            }
            else
            {
                CurrentSize = collider.radius;
                RadiusSphere.transform.localScale = Vector3(CurrentSize * 3,CurrentSize * 3,CurrentSize * 3);
    
            }
            //Clicked = true;
        }
        else if(ClickObject.ClickedOn == false)
        {
    
            LeftMenu.TurnOn = false;
            RadiusObject.transform.localScale = Vector3(0,0,0);
            RadiusSphere.transform.localScale = Vector3(0,0,0);
            //Clicked = false;  
        }
    }
    

    LeftMenu: (GUI)

    private var myLeft:float = 10;
    private var myTop:float = 100;
    private var myWidth:float = 150;
    private var myHeight:float = 40;
    
    var prefab : GameObject;
    var gridX = 5;
    var gridY = 5;
    var spacing = 2.0;
    
    var isDragging:boolean = false;
    var hit : RaycastHit;
    
    var Power = 10;
    var Strength = 10;
    
    var TurretCamera : Texture;
    static var TurnOn = false;
    
    
    function OnGUI()
    {
        //Turret Camera Window
        if(TurnOn == true){
            GUI.DrawTexture(Rect(Screen.width - 300, Screen.height - 300,260,260), TurretCamera, ScaleMode.StretchToFill, false, 30.0f);
        }
    
    
        if (GUI.RepeatButton(Rect(myLeft, myTop, myWidth, myHeight), "Moving Button" ))
            isDragging = true;
    
        if (isDragging){
            myLeft = Input.mousePosition.x - myWidth*0.5;
            myTop = Screen.height - (Input.mousePosition.y + myHeight*0.5);
        }
    
        if(Controller.OrbitCamVar == false){
            if (GUI.Button(Rect(10,10,50,50),"3D")){
                Controller.OrbitCamVar = true;
            }
        }
        else if(Controller.OrbitCamVar == true){
            if (GUI.Button(Rect(10,10,50,50),"2D")){
                Controller.OrbitCamVar = false;
            }
        }
    
        if(TurnOn == true)
        {
            GUI.BeginGroup (new Rect (2, Screen.height - 300, 170, 300));
            GUI.Box(Rect(0,0,170, 300),"Turret Info");
            GUI.Label (Rect (10, 30, 200, 30), "Name: Machine Turret");
            GUI.Label (Rect (10, 80, 200, 30), "Radius: " +Control.Radius); //Max 40!
            if (GUI.Button (Rect (170 - 65, 80, 60, 20), "Upgrade")){
                if(Control.Radius < 40){
                    Control.Radius += 3;
                }
                else
                print("Max Radius Reached!");
            }
            GUI.Label (Rect (10, 110, 200, 30), "Power: " +Power);
            if(GUI.Button (Rect (170 - 65, 110, 60, 20), "Upgrade")){
                Power += 5;
            }
            GUI.Label (Rect (10, 140, 200, 30), "Strength: " +Strength);
            if(GUI.Button (Rect (170 - 65, 140, 60, 20), "Upgrade")){
                Strength += 5;
            }
    
            if(GUI.Button (Rect (170/2 - 130/2, 250, 130, 30), "Modernise")){
                Control.ModerniseLevel += 1;
                Control.ModernisePlay = true;
            }
    
            GUI.EndGroup();
    
        }
    
    }
    

    If you do have an idea of how to help me, please give an example - my scripting it still not very strong. I would appreciate this to whom ever can help!

    Ollie


    0 0
  • 01/24/11--12:25: Tank Setup Problem
  • Hey guys, what's up? I need your help, cuz i'm having some problems with a tank setup. I'm making a tank game, and i'm in the alpha stage, but i'm already having problems. Well, i'm trying to setup a tank with the following scripts:

    var velocidade = 0.0;

    function Update () {

    var acelerar = Input.GetAxis("Vertical") * velocidade * Time.deltaTime;
    
    rigidbody.AddRelativeForce(Vector3(0,0,acelerar));
    

    }

    and

    var velocidadeDeRotacao = 100;

    function Update(){

    var virar = Input.GetAxis("Horizontal") * velocidadeDeRotacao * Time.deltaTime;

    transform.Rotate(Vector3.up * virar * Time.deltaTime);

    }

    The first script controls the aceleration of the tank, and the second controls the rotation of the tank. Its working very well, but i want more. I want to controls the tank's body and the tank's tower independently. I'm using a mouse look script in the tower. I want to when i turn around the body, the tower don't move together. So i can control them independently. That's it, thank you and sorry by me poor English, its because i'm Brazillian and 13 years old.

    Edit: This is the hierarchy:

    Tank(Empty GameObject to correct the axis) Tank (Mesh) Top (Empty GameObject to group the objects below) Canon (Mesh) Tower (Mesh) Main Camera (Camera) Bottom (Empty GameObject to group the objects below) Body (Mesh) Wheels and tracks (Mesh)


    0 0

    I am trying to scale up an object without scaling it's children. The original scale vectors for both parent and children are (1, 1, 1). The parent is named and tagged differently than the children, but all children are named and tagged the same.

    This code works to scale everything (including children) up:

    var largeSize : float;  // exposed in inspector
    
    function ScaleUp ()
    {
        var velocity = Vector3.zero;
        var targetScale = Vector3(largeSize, largeSize, largeSize);
    
        while (transform.localScale != targetScale)
        { 
            transform.localScale = Vector3.SmoothDamp(transform.localScale, targetScale, velocity, 0.5);
            yield;
        }
    }

    But I don't want everything scaled up, so I tried to differentiate the children and offset the scaling by scaling them back down. Since for (var child : Transform in transform)does include the parent transform, I tried to differentiate the children by name or by tag, as follows:

    function ScaleUp ()
    {
        var velocity = Vector3.zero;
        var targetScale = Vector3(largeSize, largeSize, largeSize);
        var childScale = Vector3(largeSize/2, largeSize/2, largeSize/2);
    
        while (transform.localScale != targetScale)
        { 
            transform.localScale = Vector3.SmoothDamp(transform.localScale, targetScale, velocity, 0.5);
            for (var child : Transform in transform)
            {
                if (child.gameObject.tag == "ChildSpecificTag")
                    child.localScale = Vector3.SmoothDamp(child.localScale, childScale, velocity, 0.5);
            }
            yield;
        }
    }
    

    This... apparently works, but also catches the parent transform in an if statement it shouldn't be caught in? The result of this code is that no scaling occurs, everything stays the same as it was. But the parent is definitely tagged differently than the children. And also named differently, and the same thing happens (no scaling - or, everything is scaled up and immediately scaled back down) if the if statement is: if (child.gameObject.name != this.gameObject.name)

    How can I apply scaling to the parent without scaling the children, or, how can I effectively differentiate the children to offset the scaling?

    ETA: I have not tried GetComponent(s)InChildren because that apparently also returns the same component in the parent, and if the parent can evade an if statement designed to weed it out when returned through Transform in transform, will it be any different using GetComponent(s)InChildren?


    0 0

    I'm working on a GUI that doesn't use Untiy's GUI system. Instead, it's composed of objects rendered by a second camera. How do I make these objects resolution independent? I gave it a shot and came up with this code:

    static public Vector3 GUIPosition(float x, float y) {
        GameObject GUICamObject  = GameObject.FindWithTag("GUICam");
        Camera GUICamera = GUICamObject.GetComponent<Camera>();
    
        Vector3 pos = GUICamera.ViewportToWorldPoint(new Vector3((x)/100,-(y-100)/100,9));
        return pos;
    }
    
    static public void Element(GameObject button, float x, float y) {
        Vector3 buttonPosition = GUIPosition(x, y);
        button.transform.position = buttonPosition;
    }
    

    But it doesn't do the trick; on higher resolutions, object positions tend to distort anyways. I'm obviously going about it wrong; what's the "right" way to make an object resolution independent?


    0 0

    I know that Unity3D uses DirectX and OpenGL at backhand for rendering. I am curious about one thing that is Resolution Independence for 2D and 3D is provided by graphical API automatically ? Or Unity3D is providing that feature Because when i change my game resolution through changes automatically, i just want to know whether this is provided by graphical API ? Or engine is providing this component for graphical API for 2D and 3D

    0 0

    where it is taken into account different screen densities? i am trying to make a gui that will be independent from resolutions and screen density. thanks!

    0 0
  • 04/05/12--10:11: Moving a single instance
  • I draw a line on which I want to add "handles", these "handles" can be moved and leave a line from their respective anchorpoint, to the new position of their respective "handle". So I made a prefab "handle" which gets instantiated on the line after a certain distance from the last "handle" was drawn. Each handle should be able to move independently, because I want to use the line length for other calculations. But when I have more than 1 instance, all overlap when I try to move a single "handle". Here's some code to elaborate: var rubberBand:GameObject; private var uniqueRubberBand:GameObject; private var rubberBandName:String; uniqueRubberBand = Instantiate(rubberBand, Vector3(linepos.x, linepos.y + 5, linepos.z), transform.rotation); rubberBandName = "RubberBand"; rubberBandName = rubberBandName.Insert(rubberBandName.Length, rubberBandNameArray.length.ToString()); Now for the line drawing, that is happening in a script attached to the prefab: function Start () { anchor = transform.position; drag = false; //Line1 line = new LineRenderer(); line = gameObject.AddComponent(LineRenderer); material = new Material(Shader.Find("Diffuse")); material.color = Color.red; line.material = material; line.SetVertexCount(0); line.SetWidth(startWidth, endWidth); //Line2 lineHelper2 = new GameObject(); lineHelper2.name = this.name + "lineHelper2"; line2 = new LineRenderer(); line2 = lineHelper2.AddComponent(LineRenderer); line2.SetVertexCount(0); line2.SetWidth(startWidth, endWidth); material2 = new Material(Shader.Find("Diffuse")); material2.color = Color.blue; line2.material = material2; //Line3 ... } function Update() {... line.SetVertexCount(2); line.SetPosition(0, anchor); line.SetPosition(1, anchor + unitVector * 25); line2.SetVertexCount(2); line2.SetPosition(0, anchor + unitVector * 25); line2.SetPosition(1, anchor + unitVector * 50); line3.SetVertexCount(2); line3.SetPosition(0, anchor + unitVector * 50); line3.SetPosition(1, transform.position); ...}

    0 0

    Hey guys and gals! For a networking project I need a framerate independent movement script (for obvious reasons). I saw this one on UnityCookie but it only moves on the global axis not the local axis. What do I need to change to make it move locally instead of globally? var speed : int = 5; var gravity = 5; private var cc:CharacterController; function Start (){ cc = GetComponent(CharacterController); } function Update (){ if(networkView.isMine){ cc.Move(Vector3(Input.GetAxis("Horizontal") * speed * Time.deltaTime, - gravity * Time.deltaTime, Input.GetAxis("Vertical") * speed * Time.deltaTime)); } else { enabled = false; } } Thanks in advance!

    0 0

    I am moving rigidbodies around with velocity. Is simply using function FixedUpdate(){ thisRigidbody.velocity.x = movement.x; } enough to make the movement framerate INDEPENDENT. versus function FixedUpdate(){ thisRigidbody.velocity.x = movement.x * Time.deltaTime; } Which seems to slowdown my game. Thanks in advance!

    0 0

    For a nice effect on a object I constantly change the scale of the transform, but this obviously changes the radius of the SphereCollider too. I need to find a way to keep the SphereCollider's radius the game, even though the scale of the transform changes. Any idea on how to do this? Help will be appreciated

    0 0

    I need to use the unity library, like Network.InitializeServer and networkView.RPC and was wondering if there was a way to do it without the bulk of the 3d engine. I realize that networkView would have to be faked, but is there a way to use the library outside of unity?

    0 0

    I am attempting to make a consistent firing rate. I have done a lot of research on figuring out consistent rates that are independent of framerate and most of the articles about it use deltaTime. However, most timers do not. I have a timer that works as long as the interval is not less that "0.2". Any number less than that has inconsistent results depending on the framerate. Specifically, when I play the project in the maximized window, versus a small window. Here is the code I am using. I know this has been beaten to death, so forgive me, please. I assume I must use some form of deltaTime multiplier somewhere. using UnityEngine; using System.Collections; public class Shooter : MonoBehaviour { // public GameObject bullet; // public Transform cam; public float interval; public float lastFire = -9999; public int shotsFired; void Update () { if(Time.time = lastFire + interval; } } I have toggled out the bullet references so that it can be easily tested. The reason I know it is inconsistent is because I implemented a test that lasts for a specific amount of time. I realize my test may be faulty and could be the actual problem. If so, please let me know. I really appreciate any and all help. Thanks, and God bless! Howey

    0 0

    How do I achieve 'correct' framerate-independent physics in Unity? As I understand it; physics logic should always be performed in the FixedUpdate() function (Application of forces, etc), but does this mean I should *scale* my forces by Time.fixedDeltaTime - similarly to the way we should scale by the [variable] deltaTime in the Update() function for game logic - or is this taken care of by the physics engine its-self? My reasoning for this is; if the number of required physics steps or the fixed update duration changes, then the forces applied will no longer be correct. However if the physics engine already takes this into account, then there is no reason to do the multiplication myself. I've read a few articles on the topic of physics in Unity, however there seems to be a lot of confusion and misinformation out there regarding how to properly achieve framerate-independence - perhaps this thread can clear some of that up? :)

    0 0

    This question is really about how do I create a prefab that allows for this. What I want is a billboard that will always face the camera while it is moving in space. I believe I do this with a gameobject that contains no mesh that has a child gameobject with the billboard mesh. A script I would add to child billboard gameobject would control its orientation to the camera. The parent gameobject would have a script attached that controls its movement. I am having trouble creating the basic prefab with the empty parent and the child with only the billboard in the Unity UI. When I try to drop in the child gameobject it merges rather creating the child. Can someone help me out with the steps to create this kind of a prefab?

    0 0

    Hello people, I've already asked this here a few times, but no one awsered, so let's try again. I've made a Character controller myself, and I tought i did things right when it comes to FPS independency, but when I tessted in other machines, it does'nt seem so. My code is pretty big. but the main lines are these: if(grounded == false) //Gravity for falling {finalmovement.y -= gravity * Time.deltaTime;} if(Input.GetButtonDown("Jump")) //Jumping {finalmovement.y = 7;} myTransform.position += (myTransform.rotation * finalmovement)*Time.deltaTime; //Overall movement I tought it is ok, if my character is not on the ground, the gravity is applied with Time.deltaTime, and if I jump, the Y of finalmovement goes to 7 and then starts to go down with the gravity to make my character move downward. But the problem is, when i have low fps, my character doesn't jump as high. why? It seems that the gravity is being applied more strongly ( I guess its because the Time between frames is bigger ), in other words, my movement is not FPS independent, even if I use Time.deltaTime. How can I solve this? Is my guess about the problem right? Thanks in advance.

    0 0
  • 02/14/14--23:21: List Problem :(
  • > using UnityEngine; > using System.Collections;> [System.Serializable] > public class pl> { public string name; public int> hp,maxhp; public int attack; }>> ________________________ > using UnityEngine; > using System.Collections;> using System.Collections.Generic;> public class player : MonoBehaviour {> public pl[] pl; public List pll;>> void Update(){>> } void OnGUI(){> if(GUILayout.Button("TIKLA")){> pll.Add(pl[0]);>> } } }> **> Sorry for very bad english :( When I add list same item.> When I change the name of the last item> Change is happening as I have all of the same item> I want to be independent of the items **

    0 0

    Hello :) I've just done double jump in my game and in a some way it's affected by changing velosity.y by game object. It means the power of second jump depends on a time(?) and changing velosity.y(?) between double clicking "Space". I want to make it independent and the jump's power is need to be the same all the time. Where am I wrong? Thanks in advance! Tomas void Update () { if(Input.GetKeyDown(KeyCode.Space)) { if(grounded) { rigidbody2D.AddForce(new Vector2(0f, jumpingForce * moving)); grounded = false; jumpCounter = 1; } else if(!grounded && jumpCounter == 1) { jumpCounter++; rigidbody2D.AddForce(new Vector2(0f, jumpingForce * moving)); //Debug.LogError("And second jump"); } } }

    0 0

    I'm creating a game on Iphone/Android. In my game, user plants a tree then have to wait for that tree grow up. Each time user opens game, I check the time when user planted the tree and the current time, then decide the tree is grew up or not. The problem is, if user plants the tree, then change device's time, he/she can cheat to make the tree grow faster. How to avoid this? Is there a way to get the "real world current time" which user can not change?

(Page 1) | 2 | 3 | .... | 5 | newer