Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Mensajes - Jose134

#76
General (Antiguo) / script para un shooter 2d
Abril 30, 2016, 08:45:04 PM
podrias hacer esto 
if (mouseWorldSpace.x > transform.position.x) {
    //El raton está a la derecha del personaje
}
if (mouseWorldSpace.x < transform.position.x) {
    //El raton está a la izquierda del personaje
}
 Y ahora, un truco que yo usaba para eso de voltear el personaje, si el personaje con el tamaño (1,1,1) mira hacia la derecha, si le asignas el tamaño (-1,1,1) el personaje mirara hacia la izquierda asi que dentro de esos ifs que he puesto antes puedes modificar su tamaño
#77
General (Antiguo) / OnTriggerStay al reves?
Abril 30, 2016, 08:38:38 PM
podrias crear un script con una array de booleanas y ponerlas true/false cuando X objeto entre/salga
var outsideObjects : GameObject[]; //Objetos a detectar
var outsideBool : bool[]; //Indica si el objecto "i" está dentro o fuera (false = fuera; true = dentro)

function Awake () {
    outsideBool = new bool[outsideObjects.Lenth];
}

function OnTriggerEnter (other : Collider) {
    for (int i = 0; i < outsideObjects.Length; i++) {
        if (other.gameObject == outsideObjects) {
            outsideBool = true;
        }
    }
}
function OnTriggerExit (other : Collider) {
    for (int i = 0; i < outsideObjects.Length; i++) {
        if (other.gameObject == outsideObjects) {
            outsideBool = false;
        }
    }
}

function Update () {
    for (int i = 0; i < outsideObjects.Length; i++) {
        if (outsideBool == true) {
            //Si el objeto "i" (outsideObjects) está dentro
        }
        else {
            //Si el objeto "i" (outsideObjects) está fuera
        }
    }
}
 Tal vez no sea el metodo mas eficiente pero es lo primero que se me ha ocurridoPD: disculpad si he cometido algun fallo en el script, hace mucho que no porgramo en JS
#78
Bueno este post tiene ya un tiempecillo pero volvi hace nada al foro y acabo de ver esto asi que me gustaria dar mi opinion Usuarios que necesitan resolver una problema, pero no incluyen código ni explican el fallo correctamente, o se explican fatal.Borrar el post (obviamente dejando un mensaje de por que ha sido borrado) Usuarios, con poco o nulo conocimiento sobre programación, que piden expresamente ayuda para adaptar/traducir un código , suyo o ajeno, a su proyecto.Igualmente, borrar el post, si mal no recuerdo vi un post sobre como traducir codigo de js a c# (o tal vez me lo haya inventado), se podria dejar un enlace a ese post Usuarios que dedican más tiempo a expresar su opinión sobre algo, que a pedir ayuda sobre un tema concreto.Nada que opinar sobre esto Usuarios que, claramente, ni se han mirado los tutoriales y documentación oficial de la web de Unity3D.com. Simplemente, como ya se hace, pasarles la documentacion basica y decirles que empiecen por ahi Usuarios que buscan más una orientación general sobe cómo hacer cosas en un Videojuegos, que sobre un problema en concreto.Esto me parece un tema interesante ya que mucha de la gente que viene aqui es la primera vez que intentan crear un juego, me pareceria una buena idea tener una serie de posts hablando sobre lo mas basico de cada apartado de la creacion de juegos (programacion, diseño, modelado, etc) y uno con las preguntas mas generales tipo ¿por donde deberia empezar? y enlaces a los posts anteriores sobre los distintos apartados. A mi me habria gustado contar con algo asi cuando yo empece a investigar sobre la creacion de juegos ya que entonces no encontre nada simple en español que me dijera como empezar
#79
Cita de: iRobb date=1461788384" data-ipsquote="" data-cite="iRobb" class="ipsQuoteOstras, muy bueno y muy original. A lo Terminator!
jajaja gracias (aunque la idea en verdad fue de mi amigo, yo solo lo programe xD)
#80
Bueno la verdad es que no sabia muy bien que titulo poner a esto, el caso es que ayer estuve haciendo esto a modo de reto (un amigo me pregunto que como lo haria yo y al no poder darle una respuesta me propuse investigar y hacerlo) El script genera un mesh con forma triangular mediante codigo y este mesh se puede transformar en un cuadrado, en un pentagono o en un hexagono dependiendo de una variable numerica (y se puede pasar directamente desde cualquier forma a cualquier otra, como por ejemplo, de triangulo a hexagono)He decidido compartirlo por si a alguien le sirve, simplemente aplicadlo a un GameObject que tenga un MeshFitler y un MeshRenderer y ya debería funcionar correctamente
using UnityEngine;
using System.Collections;

public class ShapeMorph : MonoBehaviour {

    private MeshFilter mf;
    private Mesh mesh;


    public int shape = 0;
    public float morphSpeed = 10f;

    void Awake ()
    {
        mf = GetComponent<MeshFilter>();
        mesh = new Mesh();
    }
    void Start ()
    {
        mesh = InitialMesh();
        mf.mesh = mesh;
    }

    void Update ()
    {
        shape = Mathf.Clamp(shape, 0, 3);

        if (shape ==  0) { mf.mesh.vertices = SetTriangle(); mf.mesh.name = "Triangle"; }
        if (shape ==  1) { mf.mesh.vertices = SetSquare();   mf.mesh.name = "Square";   }
        if (shape ==  2) { mf.mesh.vertices = SetPentagon(); mf.mesh.name = "Pentagon"; }
        if (shape ==  3) { mf.mesh.vertices = SetHexagon();  mf.mesh.name = "Hexagon";  }
    }

    private Mesh InitialMesh ()
    {
        Mesh newMesh = new Mesh();
        newMesh.name = "EditableMesh_Triangle";

        newMesh.vertices = new Vector3[]
        {
            new Vector3(0.5f, 1f, 0f),    //A - 0
            new Vector3(0.25f, 0.5f, 0f), //B - 1
            new Vector3(0f, 0f, 0f),      //C - 2
            new Vector3(0.5f, 0f, 0f),    //D - 3
            new Vector3(1f, 0f, 0f),      //E - 4
            new Vector3(0.75f, 0.5f, 0f)  //F - 5
        };
        newMesh.triangles = new int[]
        {
            0, 5, 1,
            5, 4, 3,
            1, 3, 2,
            1, 5, 3
        };
        newMesh.normals = new Vector3[]
        {
            -Vector3.forward,
            -Vector3.forward,
            -Vector3.forward,
            -Vector3.forward,
            -Vector3.forward,
            -Vector3.forward
        };
        newMesh.uv = new Vector2[]
        {
            new Vector2(0.5f, 1f),
            new Vector2(0.25f, 0.5f),
            new Vector2(0f, 0f),
            new Vector2(0.5f, 0f),
            new Vector2(1f, 0f),
            new Vector2(0.75f, 0.5f)
        };

        return newMesh;
    }

    private Vector3[] SetTriangle()
    {
        Vector3[] vertices = mf.mesh.vertices;

        vertices[0] = Vector3.Lerp(vertices[0], new Vector3(0.5f, 1f, 0f), morphSpeed * Time.deltaTime);
        vertices[1] = Vector3.Lerp(vertices[1], new Vector3(0.25f, 0.5f, 0f), morphSpeed * Time.deltaTime);
        vertices[2] = Vector3.Lerp(vertices[2], new Vector3(0f, 0f, 0f), morphSpeed * Time.deltaTime);
        vertices[3] = Vector3.Lerp(vertices[3], new Vector3(0.5f, 0f, 0f), morphSpeed * Time.deltaTime);
        vertices[4] = Vector3.Lerp(vertices[4], new Vector3(1f, 0f, 0f), morphSpeed * Time.deltaTime);
        vertices[5] = Vector3.Lerp(vertices[5], new Vector3(0.75f, 0.5f, 0f), morphSpeed * Time.deltaTime);

        return vertices;
    }
    private Vector3[] SetSquare ()
    {
        Vector3[] vertices = mf.mesh.vertices;

        vertices[0] = Vector3.Lerp(vertices[0], new Vector3(0f, 1f, 0f), morphSpeed * Time.deltaTime);
        vertices[1] = Vector3.Lerp(vertices[1], new Vector3(0f, 0.5f, 0f), morphSpeed * Time.deltaTime);
        vertices[2] = Vector3.Lerp(vertices[2], new Vector3(0f, 0f, 0f), morphSpeed * Time.deltaTime);
        vertices[3] = Vector3.Lerp(vertices[3], new Vector3(0.5f, 0f, 0f), morphSpeed * Time.deltaTime);
        vertices[4] = Vector3.Lerp(vertices[4], new Vector3(1f, 0f, 0f), morphSpeed * Time.deltaTime);
        vertices[5] = Vector3.Lerp(vertices[5], new Vector3(1f, 1f, 0f), morphSpeed * Time.deltaTime);

        return vertices;
    }
    private Vector3[] SetPentagon ()
    {
        Vector3[] vertices = mf.mesh.vertices;

        vertices[0] = Vector3.Lerp(vertices[0], new Vector3(0f, 0.5f, 0f), morphSpeed * Time.deltaTime);
        vertices[1] = Vector3.Lerp(vertices[1], new Vector3(0.125f, 0.25f, 0f), morphSpeed * Time.deltaTime);
        vertices[2] = Vector3.Lerp(vertices[2], new Vector3(0.25f, 0f, 0f), morphSpeed * Time.deltaTime);
        vertices[3] = Vector3.Lerp(vertices[3], new Vector3(0.75f, 0f, 0f), morphSpeed * Time.deltaTime);
        vertices[4] = Vector3.Lerp(vertices[4], new Vector3(1f, 0.5f, 0f), morphSpeed * Time.deltaTime);
        vertices[5] = Vector3.Lerp(vertices[5], new Vector3(0.5f, 1f, 0f), morphSpeed * Time.deltaTime);

        return vertices;
    }
    private Vector3[] SetHexagon ()
    {
        Vector3[] vertices = mf.mesh.vertices;

        vertices[0] = Vector3.Lerp(vertices[0], new Vector3(0f, 0.75f, 0f), morphSpeed * Time.deltaTime);
        vertices[1] = Vector3.Lerp(vertices[1], new Vector3(0f, 0.25f, 0f), morphSpeed * Time.deltaTime);
        vertices[2] = Vector3.Lerp(vertices[2], new Vector3(0.5f, 0f, 0f), morphSpeed * Time.deltaTime);
        vertices[3] = Vector3.Lerp(vertices[3], new Vector3(1f, 0.25f, 0f), morphSpeed * Time.deltaTime);
        vertices[4] = Vector3.Lerp(vertices[4], new Vector3(1f, 0.75f, 0f), morphSpeed * Time.deltaTime);
        vertices[5] = Vector3.Lerp(vertices[5], new Vector3(0.5f, 1f, 0f), morphSpeed * Time.deltaTime);

        return vertices;
    }
   
}
 Un saludo a todos
#81
Cita de: kaito date=1461702095" data-ipsquote="" data-cite="kaito" class="ipsQuote">Algo parecido me paso con otra matriz, la de color deurl="//xn--vrtices-bya.no"]vértices.No[/url] se pueden modificar las matrices de vertices, triángulos, normales, color, etc... directamente.Es necesario crear una nueva matriz o clon de la existente, modificarla, y asignarla.
   private Mesh SetTriangle(){
   Mesh m = InitialMesh();
   
   m.name = "EditableMesh_Triangle";
   Vector3[] vertices = (Vector3[])m.vertices.Clone();
   vertices[0] = new Vector3(0.5f, 1f, 0f);
   vertices[3] = new Vector3(0.75f, 0.5f, 0f);
   m.vertices = vertices;

   return m;
}
private Mesh SetSquare ()
{
   Mesh m = InitialMesh();
   
   m.name = "EditableMesh_Square";
   Vector3[] vertices = (Vector3[])m.vertices.Clone();
   vertices[0] = new Vector3(0, 1, 0);
   vertices[3] = new Vector3(1, 0, 0);
   m.vertices = vertices;
   
   return m;
}
 
Muchisimas gracias, ahora he podido arreglarlo y ademas añadi una transicion 
private Vector3[] SetTriangle()
    {
        Vector3[] vertices = mf.mesh.vertices;

        vertices[0] = Vector3.Lerp(vertices[0], new Vector3(0.5f, 1f, 0f), 10 * Time.deltaTime);
        vertices[3] = Vector3.Lerp(vertices[3], new Vector3(0.75f, 0.5f, 0f), 10 * Time.deltaTime);

        return vertices;
    }
    private Vector3[] SetSquare ()
    {
        Vector3[] vertices = mf.mesh.vertices;
       
        vertices[0] = Vector3.Lerp(vertices[0], new Vector3(0, 1, 0), 10 * Time.deltaTime);
        vertices[3] = Vector3.Lerp(vertices[3], new Vector3(1, 1, 0), 10 * Time.deltaTime);

        return vertices;
    }
 
#82
Hola gente de UnitySpain, hace siglos que no me paso por aqui y hoy me ha surgido un problema que no he conseguido arreglar de ninguna manera. Como siempre sera algo muy simple pero no lo veo xD Estaba intentando hacer un Mesh el cual se pudiera transformar de triangulo a cuadrado pero al actualizar el mesh del MeshFilter no hace nada, se queda triangulo aunque le diga que pase a ser un cuadrado :'(Os dejo el codigo completo (aunque se que no es un codigo muy agradable de leer xD)
using UnityEngine;
using System.Collections;

public class TriangleToSquare : MonoBehaviour {

    private MeshFilter mf;
    private Mesh mesh;

    public bool setTriangle;
    public bool setSquare;

    void Awake ()
    {
        mf = GetComponent<MeshFilter>();
        mesh = new Mesh();
    }

    void Start ()
    {
        mesh = InitialMesh();
        mf.mesh = mesh;
    }

    void Update ()
    {
        if (setTriangle)
        {
            Mesh newMesh = SetTriangle();
            mf.mesh = newMesh;

            setTriangle = false;
        }
        if (setSquare)
        {
            Mesh newMesh = SetSquare();
            mf.mesh = newMesh;

            setSquare = false;
        }    
    }

    private Mesh InitialMesh ()
    {
        Mesh newMesh = new Mesh();
        newMesh.name = "EditableMesh_Triangle";

        newMesh.vertices = new Vector3[]
        {
            new Vector3(0.5f, 1f, 0f),   //A - 0
            new Vector3(0f, 0f, 0f),     //B - 1
            new Vector3(1f, 0f, 0f),     //C - 2
            new Vector3(0.75f, 0.5f, 0f) //D - 3
        };
        newMesh.triangles = new int[]
        {
            3, 1, 0,
            3, 2, 1
        };
        newMesh.normals = new Vector3[]
        {
            -Vector3.forward,
            -Vector3.forward,
            -Vector3.forward,
            -Vector3.forward
        };
        newMesh.uv = new Vector2[]
        {
            new Vector2(0, 1),
            new Vector2(0, 0),
            new Vector2(1, 0),
            new Vector2(1, 1)
        };

        return newMesh;
    }

    private Mesh SetTriangle()
    {
        Mesh m = InitialMesh();

        m.name = "EditableMesh_Triangle";
        m.vertices[0] = new Vector3(0.5f, 1f, 0f);
        m.vertices[3] = new Vector3(0.75f, 0.5f, 0f);
       
        return m;
    }
    private Mesh SetSquare ()
    {
        Mesh m = InitialMesh();

        m.name = "EditableMesh_Square";
        m.vertices[0] = new Vector3(0, 1, 0);
        m.vertices[3] = new Vector3(1, 0, 0);
       
        return m;
    }
   
}
 Muchas gracias por vuestra ayuda [EDIT]Os adjunto esta foto por si sirve de algo, es un dibujito que hice mientras pensaba como hacer esto (disculpad la calidad, no se enfocar bien con mi telefono)
#83
Cita de: MiguelS date=1458953562" data-ipsquote="" data-cite="MiguelS" class="ipsQuote">  Link caido /quote]resubido, gracias por avisar (y disculpa responder un mes tarde pero hace siglos que no me paso por el foro)
#84
General (Antiguo) / Duda con input en Visual C#
Enero 06, 2016, 07:54:57 AM
[quote author=francoe1 date=1452029363" data-ipsquote="" data-cite="francoe1" class="ipsQuote">¿Estas Loco Viejo?¿Quieres hacer un Motor Gráfico?¿Un Juego? ¿Que ventajas tendrías al hacer esto con Visual Studio?Para saber de Game Loop deberias leer esto te servirá mucho : http://tutorials.jenkov.com/flex-tetris/overview-of-implementation.html]http://tutorials.jenkov.com/flex-tetris/overview-of-implementation.htmlBueno con eso tendrias una idea, pero lo que estás intentando hacer es una pérdida de tiempo, aunque si necesitas mas ayuda yo no tengo problemas en darte una mano, ya que también tuve la misma loca idea de hacer algo como lo que estás haciendo... El resultado no es algo que te enorgullezca tanto.. Jajaja [/quote]De viejo nada que todavia tengo 15 añitos xDLa idea al principio era hacer un motor grafico 2D pero me estuve viendo unos videos para tener una referencia y en una tarde consegui hacerlo (aunque aun habria que mejorarlo un poco) asi que decidi intentar hacer un juego entero junto con un mini-GameEnigneY ventajas de Visual Studio... Que es el IDE que conozco y llevo bastante tiempo usandolo, sinceramente no hay ningun otro motivo xDYa sabia que era una perdida de tiempo xD solo lo hago a modo de reto personal Muchas gracias por ese tutorial me ha sido de ayuda, por cierto, consegui hacer que funcionara la parte del codigo del GameForm_KeyDown asi que puedo empezar con la clase Input a partir de ahi
#85
General (Antiguo) / Duda con input en Visual C#
Enero 05, 2016, 05:32:48 PM
Hola a todos compañeros de UnitySpain, me he alejado un poco de Unity para dedicarme a un proyectillo en visual c# pero he llegado a un punto en el que no tengo ni idea de que hacer. Me gustaria hacer un sistema de input (mas o menos con las mismas funciones que tiene el de unity) pero no se muy bien como recoger la input (tambien estoy teniendo problemillas para implementar el game loop ya que no se muy bien que funciones deberia poner dentro de el loop y tal) Os dejo algo de codigo que tal vez os pueda ser de ayuda ( la clase Input.cs no la pongo porque basicamente solo la he creado, no he hecho nada en ella todavia xD )(La optimizacion del codigo ahora mismo es lo de menos y muchas de las cosas que tengo hechas son solo provisionales, me gustaria optimizarlo pero primero quiero conseguir que funcione todo) Game.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Threading;
using System.Threading.Tasks;

namespace _2DGameTest
{
    class Game
    {
        //---------Constants---------\
        public const int Canvas_Width = 600;
        public const int Canvas_Height = 400;

        //---------Variables---------\
        private GraphicsEngine graphicsEngine;
        private Camera _cam;
        public Camera cam
        {
            get { return _cam; }
        }
       
        public Input input = new Input();
       
        public List<GameObject> gameObjectsInstances = new List<GameObject>();
        private Thread gameLoopThread;

        private bool running;

        //---------Constructor---------\
        public Game ()
        {
            _cam = new Camera(0, 0);
        }

        #region GraphicsEngine
        public void StartGraphics (Graphics g)
        {
            graphicsEngine = new GraphicsEngine(g, this);
            graphicsEngine.Initialize();
        }
        public void StopGraphics ()
        {
            graphicsEngine.Stop();
        }
        #endregion

        public void StartGame ()
        {
            gameLoopThread = new Thread(new ThreadStart(GameLoop));
            gameLoopThread.Start();

            running = true;
        }
        public void StopGame ()
        {
            running = false;
            gameLoopThread.Abort();
        }

        public void GameLoop ()
        {
            while (running)
            {

                Thread.Sleep(1);
            }
        }
    }
}
 GameObject.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Threading.Tasks;

namespace _2DGameTest
{
    class GameObject
    {
        //---------Image---------\
        public Bitmap sprite;

        //---------Position---------\
        public float x;
        public float y;
        //---------Size---------\
        private float _width;
        private float _height;

        public float width
        {
            get { return _width; }
        }
        public float height
        {
            get { return _height; }
        }

        //---------Constructor---------\
        public GameObject (Bitmap sprite, float x, float y)
        {
            this.sprite = sprite;
            this.x = x;
            this.y = y;
            this._width = sprite.Width;
            this._height = sprite.Height;
        }
    }
}
 Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _2DGameTest
{
    public partial class GameForm : Form
    {
        private Game game = new Game();

        private GameObject player;
        private GameObject enemy;

        public GameForm()
        {
            InitializeComponent();

            player = new GameObject(_2DGameTest.Properties.Resources.Player, 125, 80);
            enemy = new GameObject(_2DGameTest.Properties.Resources.Enemy, 200, 80);
        }

        private void canvas_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = canvas.CreateGraphics();
            game.StartGraphics(g);
           
            game.gameObjectsInstances.Add(player);
            game.gameObjectsInstances.Add(enemy);
        }

        private void GameForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            game.StopGraphics();
        }
       
        /* Esto por algun motivo no funciona y seria una buena referencia para empezar :c
        private void GameForm_KeyDown(object sender, KeyEventArgs e)
        {

            char key = (char)e.KeyValue;

            switch (key)
            {
                case 'W':
                    game.gameObjectsInstances[0].y -= 10;
                    break;
                case 'A':
                    game.gameObjectsInstances[0].x -= 10;
                    break;
                case 'S':
                    game.gameObjectsInstances[0].y += 10;
                    break;
                case 'D':
                    game.gameObjectsInstances[0].x += 10;
                    break;
            }

        }
        */
    }
}
#86
Post actualizado
#87
General (Antiguo) / Feliz navidad
Diciembre 25, 2015, 11:01:44 AM
Feliz Navidad!
#88
General (Antiguo) / Buenas
Octubre 27, 2015, 03:34:10 PM
yo estoy en tu misma situacion. También llevo 2 años aprox con unity y ninguno de mis proyectos lo he podido terminar (descontando un flappy bird y este juego http://unityspain.com/topic/15723-destroythoseasteroids-juego-hecho-en-un-dia/) y también soy programador y uso C#! (Bueno, en realidad empece con unityscript pero luego me pase a C#) Suerte con tu proyecto!
#89
Aqui teneis una pequeña mejora que le he añadido al script. Ahora se puede modificar el eje al que se le aplica el movimiento y he añadido una variable para añadir offset al comenzar, es decir, que espera X tiempo y empiece a moverse. No explicare como funcionan los cambios hechos a no ser que alguien me lo pida 
using UnityEngine;
using System.Collections;

public class ObjectMovement : MonoBehaviour {

public enum Axis {
   x,
   y,
   z
}
public Axis axis;

public float posMultiplier;
public float speedMultiplier;
public float startTimeOffset;

private float angle;
private float startPos;
private float startTime;

void Awake () {

   if (axis == Axis.x) { startPos = transform.position.x; }
   if (axis == Axis.y) { startPos = transform.position.y; }
   if (axis == Axis.z) { startPos = transform.position.z; }

}

void Update () {

   if (startTime >= startTimeOffset)
   {

   angle += Time.deltaTime * speedMultiplier;
   if (angle >= 360) {
      angle = 0;
   }
   
   float cos = Mathf.Cos(angle);
   float pos = (startPos + cos) * posMultiplier;

   if (axis == Axis.x) { transform.position = new Vector3(pos, transform.position.y, transform.position.z); }
   if (axis == Axis.y) { transform.position = new Vector3(transform.position.x, pos, transform.position.z); }
   if (axis == Axis.z) { transform.position = new Vector3(transform.position.x, transform.position.y, pos); }


   }
   else
   {
      startTime += Time.deltaTime;
   }
}
}
 
#90
General (Antiguo) / Generación de mapa
Octubre 22, 2015, 08:03:25 PM
Añade WaitForSeconds dentro del for de la x y del for de la z. Eso ayudara a que unity no pete al generar el mapa. De todos modos como ya te han dicho eso son 100.000 gameObjects en la escena y eso consume mucho