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"

older | 1 | (Page 2) | 3 | 4 | 5 | newer

    0 0

    Hi! I started with unity some weeks ago. Im trying to make a simple side-shooter 2d game, i had set the camera with a script to 1280x720 so i can test it with my phone on landscape orientation. There are a lot of resolutions for android, how should i work around this for not getting sprites scaled or off screen? Thanks :)

    0 0

    With this script it makes the child objects rotate based on the parents position, I want to implement something that will allow me to change the parents scale but not have that affect the child scale. Any ideas how I could implement that into this script ? using UnityEngine; using System.Collections; public class Tutorial_3_Q1 : MonoBehaviour { public Transform _parent; private float eulerAngles; void start() { } void Update() { transform.RotateAround(_parent.position, _parent.rotation.eulerAngles, 50 * Time.deltaTime); print(transform.eulerAngles.x); print(transform.eulerAngles.y); print(transform.eulerAngles.z); } void OnGUI() { GUI.Label(new Rect (10, 10, 200, 20),"Euler Angle x ="+ transform.eulerAngles.x); GUI.Label(new Rect(10, 30, 200, 40), "Euler Angle y ="+ transform.eulerAngles.y); GUI.Label(new Rect(10, 50, 200, 60), "Euler Angle z ="+ transform.eulerAngles.z); } }

    0 0

    Does all of builds will be little endian format regardless of the final build platform? I'd rather not use BitConverter class with: if (BitConverter.IsLittleEndian) Array.Reverse(bytes); If it will be little endian anyway, creating, checking and reversing after is a waste of resources. I already build my custom byte converter class which threats everything as little endian. But the question about multiplatform stays.

    0 0

    I have this code and been messing around with time.deltatime for quite a long time now, not sure why it isnt frame independant, please help. void Update() { Vector3 velocity = bulletSpeed * transform.forward + gravity; //Debug.Log (transform.position); //Debug.Log (velocity); gravity += new Vector3 (0, -9.8f, 0); newPos = velocity * Time.deltaTime + transform.position; direction = newPos - oldPos; float dist = direction.magnitude; if(Physics.Raycast(oldPos,direction,out hit,dist,layersToCheck)) { //Debug.Log("hit Object name: " + hit.collider.gameObject.name); Destroy(gameObject); } else { oldPos = transform.position; transform.position = newPos; }

    0 0

    I know what it does but I'm not sure how to use it in my code All the answers I've found just point to how it's a good way to move or animate when Time.timescale == 0 I need some simple example code I have 2 moving Cubes, I want one to keep moving when game is paused

    0 0

    Hello, I can't get my movement to be framerate independent. Here's the code I using inside Update: void Update () { if (Input.GetKeyDown(KeyCode.Escape)) Application.Quit(); if (Input.anyKey) { velx ++; } else { velx *= drag; } velx = Mathf.Clamp(velx, -max_velx, max_velx); Vector3 delta = new Vector3(velx * Time.deltaTime, 0, 0); transform.Translate(delta); } When I change the quality of the graphics in the game.. the player speed changes considirably. I can't see where the problem might come from, since I'm scaling the velocity by the time spent on the frame.

    0 0

    In my project I have Unity's [CharacterController](http://docs.unity3d.com/Manual/class-CharacterController.html). This is the code that made it move. It's working great when using fixed timestep. vel.x *= friction; vel.z *= friction; vel.x += input.x; vel.z += input.z; cc.Move (vel); I want my game to support unlocked framerate so the character's movement should be updated on per-frame basis. The problem is that the acceleration is really inconsistent. Eventually all framerates hit the maximum speed (they get closer to it every frame), but 1000 FPS reaches it almost instantly, while 15 FPS takes a long time to accelerate. After pondering about it, it makes sense, but I wasn't able to make the acceleration consistent... What is the mathematical solution to this? Any tips are appreciated!

    0 0
  • 03/25/16--04:38: Resolution independence
  • Hi, I have drag mechanic in my game and I want to have same experience in all devices. I've done this before in another game engine and now that Unity gives us Dpi with Screen.DPI, it should be much easier to achieve, but I can't figure it out for the love of the god. My theory is you have to divide the delta movement of touch with Screen.Dpi to normalize the movement and make it same across devices with different screen sizes and dpi's: (touch0.deltaPosition.x / dpi) * SENSITIVITY * Time.deltaTime; But this doesn't work. Would someone please tell me why? I've done extensive search on this but surprisingly nothing much can be found. Thanks in advance and regards.

    0 0

    Jumping and framerate independence. Tried solutions, didn't like. Here is simple example that demonstrates the point - empty scene, attached this to gameobject: using UnityEngine; using System.Collections; public class jumpTest : MonoBehaviour { private float velocityY = 0; private int counter = 0; private float jumpHeight = 0.1f; private Vector3 gravity = new Vector3(0,-.1f,0); // Update is called once per frame void Update () { // gravity framerate independent float gravityY = gravity.y * Time.deltaTime; if (counter == 0) { // Jump is impulse, wont mult jumpHeight // @see http://answers.unity3d.com/questions/1156824/forcemode2dimpulse-do-we-need-timedeltatime.html // velocity framerate independent velocityY += (jumpHeight + gravityY); } else { velocityY += gravityY; } if (velocityY

    0 0

    I keep coming back to this because this is still an issue to me. I switched my focus to other Unity and C# studies but now I'm back. I've seen some videos. Still stuck. Situation: I have a small Terrain and two spheres. I want to give orders to each sphere separately to move to different locations...at the same time though. I want to do it in a "classic" RTS fashion (Ideally, anyway) by left mouse click on unit and then right mouse click on destination. I'm thinking I need a private bool isSelected switch for the left mouse click and then some sort of raycast to mark the destination. But I can't quite figure out exactly how to write this in code. I know how to use raycasting...I can make ALL the units go to a single right-click location, that's easy...I just can't make two units go to separate locations at the same time. I've done all this with physics, without physics, with NavMesh and without NavMesh...all of that. Bummer. I've been spending a lot of time on this but I feel like I'm missing something really basic that's keeping me from accomplishing my task.

    0 0

    I created a script for sinusoidal motion. The movement works perfectly, but the various objects with this script do not move independently. What could I do to solve this problem? Here is the script: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Enemy4 : Nave { public float horizontalSpeed; public int yFactor; private float count = 3; private Vector3 s; private bool setPos = false; private float x; private float y; // Use this for initialization void Start () { x = 0; y = 0; s = transform.position; side = Side.defside.ENEMY; } // Update is called once per frame void Update () { y += yFactor * Time.deltaTime; x = Mathf.Sin (Time.time) * horizontalSpeed; transform.position = s + new Vector3 (x,y, 0); } }

    0 0

    Criei um script o qual faz um GameObject se mover de forma senoidal. O movimento ocorre perfeitamente, mas quando mais de um GameObject contendo este script está em cena todos se movem como um espelho um do outro e não de forma relativa, deixando o jogo muito artificial. Tentei usar posicionamento local e mesmo assim não consegui resolver o problema. Eis o código: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Enemy4 : Nave { public float horizontalSpeed; public int yFactor; private float count = 3; private Vector3 s; private bool setPos = false; private float x; private float y; // Use this for initialization void Start () { x = 0; y = 0; s = transform.position; side = Side.defside.ENEMY; } // Update is called once per frame void Update () { y += yFactor * Time.deltaTime; x = Mathf.Sin (Time.time) * horizontalSpeed; transform.position = s + new Vector3 (x,y, 0); } }

    0 0

    so I am making a shooting game where the game spawns 5 enemies from a prefab. the problem is that when the enemy clone gets instantiated it works properly, but when the enemy clone detects the player, all of the enemy clones start shooting at the player. I want the enemy clone that detected the player to be the only one that will shoot at the player, and not all of the enemy clones. here is the code for my enemy object: using UnityEngine; using System.Collections; public class enemyMovement : MonoBehaviour { Rigidbody2D rb2d; public Transform target; private float nextFire; public float turnTime; public float speed; public float trackSpeed; int turn; public GameObject particles; int enemyHp = 100; private float explodeTime; // Use this for initialization void Start() { rb2d = GetComponent(); particles.gameObject.SetActive(false); target = GameObject.Find("fighter").transform; } float h, v, zed; public static bool check = true; // Update is called once per frame void Update() { float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); if (check == true) { if (Time.time > nextFire) { nextFire = Time.time + turnTime; turn = Random.Range(0, 5); switch (turn) { case 1: h = horizontal - 1; v = vertical; rb2d.transform.eulerAngles = new Vector3(0, 0, 90); // Debug.Log("left"); break; case 2: h = horizontal + 1; v = vertical; rb2d.transform.eulerAngles = new Vector3(0, 0, 270); // Debug.Log("right"); break; case 3: h = horizontal; v = vertical + 1; rb2d.transform.eulerAngles = new Vector3(0, 0, 0); // Debug.Log("up"); break; case 4: h = horizontal; v = vertical - 1; rb2d.transform.eulerAngles = new Vector3(0, 0, 180); // Debug.Log("down"); break; } } Vector2 temp = new Vector2(h, v); rb2d.AddForce(temp * Time.deltaTime * speed); } else if (check == false) { Vector3 vectorToTarget = target.position - transform.position; float angle = (Mathf.Atan2(vectorToTarget.y, vectorToTarget.x) * Mathf.Rad2Deg) - 90; Quaternion q = Quaternion.AngleAxis(angle, Vector3.forward); transform.rotation = Quaternion.Slerp(transform.rotation, q, Time.deltaTime * speed); if ((target.position.x > rb2d.position.x + 7 && target.position.x rb2d.position.x - 15) || (target.position.y > rb2d.position.y + 5 && target.position.y rb2d.position.y - 15)) { transform.position += transform.up * Time.deltaTime * trackSpeed; }//if the enemy is within the range of the player, the enemy will follow the player. else if(target.position.x > rb2d.position.x + 15 || target.position.x rb2d.position.y + 15 || target.position.y explodeTime) { explodeTime = Time.time + .5f; particles.gameObject.SetActive(false); } } // Debug.Log(check); } void OnTriggerEnter2D(Collider2D other) { if(other.gameObject.CompareTag("player fighter")) { check = false; }// if the player touches the onTrigger for the enemy, the enemy will follow the player. } void OnCollisionEnter2D(Collision2D other) { if (other.gameObject.CompareTag("player bullet")) { Destroy(other.gameObject); enemyHp -= bulletMove.bulletDamage; } } }

    0 0

    Just as the title says. How can I make the position of an object independent again after making it dependent earlier. This is what I have right now: if(ItemPickedUp == true){ // If you press the E key. if(Input.GetKeyDown("e")){ // The CarryableObject becomes a child of the Utility Props again. CarryableObject.transform.parent = UtilityProps.transform; // The drop position. CarryableObject.transform.position = new Vector3(Character.transform.position.x, Character.transform.position.y, Character.transform.position.z + OffsetDropPosition); // The rotation is no longer relative to the Character. CarryableObject.transform.rotation = Character.transform.rotation; // The gravity gets reenabled. CarryableObject.GetComponent().useGravity = true; // The child collider if-statements. if(Child1 != null){ Child1.GetComponent().enabled = true; } if(Child2 != null){ Child2.GetComponent().enabled = true; } if(Child3 != null){ Child3.GetComponent().enabled = true; } if(Child4 != null){ Child4.GetComponent().enabled = true; } } }

    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!

older | 1 | (Page 2) | 3 | 4 | 5 | newer