Cuber01

Member
  • Content count

    7
  • Joined

  • Last visited

Community Reputation

121 Neutral

About Cuber01

  • Rank
    Newbie

Personal Information

  • Interests
    |programmer|
  1. Hello I am working in unity with c#. I am working on a 2D platformer for mobile. The way I currently have it setup is one joystick that moves the charatcer makes the charatcer arm rotate and make the charatcer shoot the gun when pressed. Which all workd fine. But the problem I am having is the bullets from the gun are not going in the correct direction. Currently the bullets go to the rigtht no matter where I point the gun. I have tried in the raycats to use transform.right and transform.forward. All end up with the same result. the firepoint for the gun is an empty game object and the firepoint in the script is an tranfrom. I tried changing it to an GameObject in the script but I got the same results. If someone could please help it would be grealty appreciated!!! Here is the shoot function with the raycast. public void Shoot ()     {         Vector3 firePointPosition = new Vector3 (firePoint.position.x, firePoint.position.y, 0f);         RaycastHit2D hit = Physics2D.Raycast (firePointPosition, firePoint.transform.right, 100, whatToHit, 0f);           Debug.DrawRay(firePointPosition, firePoint.transform.right * 100);         if (hit.collider != null)         {             Debug.DrawLine(firePointPosition, hit.point, Color.red);             Enemy enemy = hit.collider.GetComponent<Enemy>();             if (enemy != null)             {                 enemy.DamageEnemy(Damage);                 //Debug.Log("We hit " + hit.collider.name + "and did " + Damage + "damage");             }         }           if (Time.time >= timeToSpawnEffect)         {             Vector3 hitPos;             Vector3 hitNormal;               if (hit.collider == null)             {                 hitPos = (firePointPosition) * 30;                 hitNormal = new Vector3(9999, 9999, 9999);             }             else             {                 hitPos = hit.point;                 hitNormal = hit.normal;             }                                             Effect(hitPos, hitNormal);             timeToSpawnEffect = Time.time + 1 / effectSpawnRate;         }     }   And the effect method    void Effect (Vector3 hitPos, Vector3 hitNormal)     {         Transform trail = Instantiate (BulletTrailPrefab, firePoint.position, firePoint.rotation) as Transform;         LineRenderer Lr = trail.GetComponent<LineRenderer>();           if (Lr != null)         {             Lr.SetPosition(0, firePoint.position);             Lr.SetPosition(1, hitPos);           }           Destroy(trail.gameObject, 0.04f);           if (hitNormal != new Vector3(9999,9999,9999))         {             Transform hitParticle = Instantiate(HitPrefab, hitPos, Quaternion.FromToRotation (Vector3.right, hitNormal))as Transform;             Destroy(hitParticle.gameObject, 1f);         }           Transform clone = Instantiate (MuzzleFlashPrefab, firePoint.position, firePoint.rotation) as Transform;         clone.parent = firePoint;         float size = Random.Range(0.6f, 0.9f);         clone.localScale = new Vector3 (size, size, size);         Destroy(clone.gameObject, 0.02f);           //Shake the Camera         camShake.Shake(camShakeAmt, camShakeLength);           //Play shoot sound         audioManger.PlaySound(weaponShootSound);     }  
  2. am working on a 2D platformer and i am tring to add mobile controls. What I want is for the joystick that moves the player (which works) to also wehn you touch the joystick for the player to shoot. I tried usuing cross platform Input Manger in replace of input but all it did was make it so notjing happend the player will still not shoot. If someone could help me out that would be great!!!! Here is the code in c# void Update ()     {         if (fireRate == 0)         {             if (CrossPlatformInputManager.GetButtonDown("Fire1"))                  {                 Shoot();                       }         }         else         {             if (CrossPlatformInputManager.GetButton ("Fire1") && Time.time > timeToFire)              {                 timeToFire = Time.time + 1 / fireRate;                 Shoot();             }         }     }   And the Shoot Method    void Shoot ()     {         Vector2 joyStickPosition = new Vector2(Camera.main.ScreenToWorldPoint(CrossPlatformInputManager.mousePosition).x, Camera.main.ScreenToWorldPoint(CrossPlatformInputManager.mousePosition).y);         Vector2 firePointPosition = new Vector2 (firePoint.position.x, firePoint.position.y);         RaycastHit2D hit = Physics2D.Raycast (firePointPosition, joyStickPosition-firePointPosition, 100, whatToHit);           Debug.DrawLine(firePointPosition, (joyStickPosition - firePointPosition)*100, Color.cyan);          if (hit.collider != null)         {             Debug.DrawLine(firePointPosition, hit.point, Color.red);             Enemy enemy = hit.collider.GetComponent<Enemy>();             if (enemy != null)             {                 enemy.DamageEnemy(Damage);                 //Debug.Log("We hit " + hit.collider.name + "and did " + Damage + "damage");             }         }  
  3. I am working on a 2D platformer and I am adding mobile controls. I am trying to get the player to shoot when you touch and move the joystick. I tried to change all of the Input to CrossPlatformInputManger but when I use the joystick nothing happens. Please any sugggestions will be helpful! Thanks!!!! Here is what is in the update method   void Update () {         if (fireRate == 0)         {             if (CrossPlatformInputManager.GetButtonDown("Fire1"))                  {                 Shoot();                       }         }         else         {             if (CrossPlatformInputManager.GetButton ("Fire1") && Time.time > timeToFire)              {                 timeToFire = Time.time + 1 / fireRate;                 Shoot();             }         }     }   and the Shoot Method   void Shoot ()     {         Vector2 joyStickPosition = new Vector2(Camera.main.ScreenToWorldPoint(CrossPlatformInputManager.mousePosition).x, Camera.main.ScreenToWorldPoint(CrossPlatformInputManager.mousePosition).y);         Vector2 firePointPosition = new Vector2 (firePoint.position.x, firePoint.position.y);         RaycastHit2D hit = Physics2D.Raycast (firePointPosition, joyStickPosition-firePointPosition, 100, whatToHit);           Debug.DrawLine(firePointPosition, (joyStickPosition - firePointPosition)*100, Color.cyan);          if (hit.collider != null)         {             Debug.DrawLine(firePointPosition, hit.point, Color.red);             Enemy enemy = hit.collider.GetComponent<Enemy>();             if (enemy != null)             {                 enemy.DamageEnemy(Damage);                 //Debug.Log("We hit " + hit.collider.name + "and did " + Damage + "damage");             }         } 0down votefavorite   I am working on a 2D platformer and I am adding mobile controls. I am trying to get the player to shoot when you touch and move the joystick. I tried to change all of the Input to CrossPlatformInputManger but when I use the joystick nothing happens. Please any sugggestions will be helpful! Thanks!!!! Here is what is in the update method void Update () { if (fireRate == 0) { if (CrossPlatformInputManager.GetButtonDown("Fire1")) { Shoot(); } } else { if (CrossPlatformInputManager.GetButton ("Fire1") && Time.time > timeToFire) { timeToFire = Time.time + 1 / fireRate; Shoot(); } } } And the Shoot method void Shoot () { Vector2 joyStickPosition = new Vector2(Camera.main.ScreenToWorldPoint(CrossPlatformInputManager.mousePosition).x, Camera.main.ScreenToWorldPoint(CrossPlatformInputManager.mousePosition).y); Vector2 firePointPosition = new Vector2 (firePoint.position.x, firePoint.position.y); RaycastHit2D hit = Physics2D.Raycast (firePointPosition, joyStickPosition-firePointPosition, 100, whatToHit); Debug.DrawLine(firePointPosition, (joyStickPosition - firePointPosition)*100, Color.cyan); if (hit.collider != null) { Debug.DrawLine(firePointPosition, hit.point, Color.red); Enemy enemy = hit.collider.GetComponent<Enemy>(); if (enemy != null) { enemy.DamageEnemy(Damage); //Debug.Log("We hit " + hit.collider.name + "and did " + Damage + "damage"); }
  4. Thanks for the respose I did get it to work but now I ran into another issue and I am wodering if you can help me?   The arm now rotates but the bullet trail that comes out of the gun to kill the enemies dosent follow the joystick.   I have tried to change the Input to CrossPlatformInputManger but all it does is stay in one place   here is the code that shoots    void Shoot ()     {         Vector2 mousePosition = new Vector2 (Camera.main.ScreenToWorldPoint (Input.mousePosition).x, Camera.main.ScreenToWorldPoint (Input.mousePosition).y);         Vector2 firePointPosition = new Vector2 (firePoint.position.x, firePoint.position.y);         RaycastHit2D hit = Physics2D.Raycast (firePointPosition, mousePosition-firePointPosition, 100, whatToHit);           Debug.DrawLine(firePointPosition, (mousePosition - firePointPosition)*100, Color.cyan);          if (hit.collider != null)         {             Debug.DrawLine(firePointPosition, hit.point, Color.red);             Enemy enemy = hit.collider.GetComponent<Enemy>();             if (enemy != null)             {                 enemy.DamageEnemy(Damage);             }         }
  5. I am making a 2D Platformer in unity using c#. I am working on adding mobile controls to the game. Right now I have one joystick that controls the player movement as well as rotating the arm to shoot the enemies that come from above Issues I am running into When I move the joystick to move the player the arm does rotate but the bullet trail that kills the enemies does not follow as well. What I have done I did import the CrossPlatformInput libary to the script. I tried to change the Input.mousePosition to CrossPlatformInputManger but all it did was stay in one place. Here is the weapon script with the shoot method void Shoot () { Vector2 mousePosition = new Vector2 (Camera.main.ScreenToWorldPoint (Input.mousePosition).x, Camera.main.ScreenToWorldPoint (Input.mousePosition).y); Vector2 firePointPosition = new Vector2 (firePoint.position.x, firePoint.position.y); RaycastHit2D hit = Physics2D.Raycast (firePointPosition, mousePosition-firePointPosition, 100, whatToHit); Debug.DrawLine(firePointPosition, (mousePosition – firePointPosition)*100, Color.cyan); if (hit.collider != null) { Debug.DrawLine(firePointPosition, hit.point, Color.red); Enemy enemy = hit.collider.GetComponent<Enemy>(); if (enemy != null) { enemy.DamageEnemy(Damage); } }
  6. Hello, I have been working on a 2D platformer and right now I have set up in a way that makes the arm follow the mouse cursor. I want to be able to have it so that when you move the joystick it moves the arm as well. Here is the arm rotation script using UnityEngine; using System.Collections; public class ArmRotation : MonoBehaviour { public int rotationOffset = 0; void Update () { Vector3 mousePos = Input.mousePosition; mousePos.z = 5.23f; Vector3 objectPos = Camera.main.WorldToScreenPoint(transform.position); mousePos.x = mousePos.x – objectPos.x; mousePos.y = mousePos.y – objectPos.y; float angle = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle)); } }
  7. Hello,   I have been working on a 2D Platformer and I am at the point where I want to add mobile controls for the phone. I am new to unity so I need some help.   Here is what I have:      The basic gameplay is waves of aliens come from above and you have to shoot them. The aming is right now controlled by the mouse. The gun follows the mouse      basic movement is controlled with the arrow keys and space bar      I also have the Unity standard assets in my project as well Here is what I want:      I want to have 2 joysticks one that controls the movement of the player and one that controls the aming and shooting      For shooting I want to be already shooting when you place your finger on the joystick   If someone could please help me with it. Tell me what to add and stuff like that would be really appreciated!!   Here are some of my scripts:   PlayerController:            using System; using UnityEngine; using UnityStandardAssets.CrossPlatformInput;   namespace UnityStandardAssets._2D {     [RequireComponent(typeof (PlatformerCharacter2D))]     public class Platformer2DUserControl : MonoBehaviour     {         private PlatformerCharacter2D m_Character;         private bool m_Jump;             private void Awake()         {             m_Character = GetComponent<PlatformerCharacter2D>();         }             private void Update()         {             if (!m_Jump)             {                 // Read the jump input in Update so button presses aren't missed.                 m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");             }         }             private void FixedUpdate()         {             // Read the inputs.             bool crouch = Input.GetKey(KeyCode.LeftControl);             float h = CrossPlatformInputManager.GetAxis("Horizontal");             // Pass all parameters to the character control script.             m_Character.Move(h, crouch, m_Jump);             m_Jump = false;         }     } }   Character 2D script        using System; using UnityEngine;   namespace UnityStandardAssets._2D {     public class PlatformerCharacter2D : MonoBehaviour     {         [SerializeField] private float m_JumpForce = 400f;                  // Amount of force added when the player jumps.         [Range(0, 1)] [SerializeField] private float m_CrouchSpeed = .36f;  // Amount of maxSpeed applied to crouching movement. 1 = 100%         [SerializeField] private bool m_AirControl = false;                 // Whether or not a player can steer while jumping;         [SerializeField] private LayerMask m_WhatIsGround;                  // A mask determining what is ground to the character           [SerializeField]         string landingSoundName = "LandingFootsteps";           private Transform m_GroundCheck;    // A position marking where to check if the player is grounded.         const float k_GroundedRadius = .2f; // Radius of the overlap circle to determine if grounded         private bool m_Grounded;            // Whether or not the player is grounded.         private Transform m_CeilingCheck;   // A position marking where to check for ceilings         const float k_CeilingRadius = .01f; // Radius of the overlap circle to determine if the player can stand up         private Animator m_Anim;            // Reference to the player's animator component.         private Rigidbody2D m_Rigidbody2D;         private bool m_FacingRight = true;  // For determining which way the player is currently facing.           private Transform playerGraphics;          // reference to the graphics so we can chnage direction           AudioManger audioManger;           private void Awake()         {             // Setting up references.             m_GroundCheck = transform.Find("GroundCheck");             m_CeilingCheck = transform.Find("CeilingCheck");             m_Anim = GetComponent<Animator>();             m_Rigidbody2D = GetComponent<Rigidbody2D>();             playerGraphics = transform.FindChild("Graphics");             if (playerGraphics == null)             {                 Debug.LogError("Lets freak out! There is no 'Graphics' object as a child of the player");              }                     }           void Start ()         {             audioManger = AudioManger.instance;             if(audioManger == null)             {                 Debug.LogError("THIS IS WHY WE WRIGHT ERROR MESSAGES: No audioManger found.");             }         }           private void FixedUpdate()         {             bool wasGrounded = m_Grounded;                 m_Grounded = false;               // The player is grounded if a circlecast to the groundcheck position hits anything designated as ground             // This can be done using layers instead but Sample Assets will not overwrite your project settings.             Collider2D[] colliders = Physics2D.OverlapCircleAll(m_GroundCheck.position, k_GroundedRadius, m_WhatIsGround);             for (int i = 0; i < colliders.Length; i++)             {                 if (colliders[i].gameObject != gameObject)                     m_Grounded = true;             }             m_Anim.SetBool("Ground", m_Grounded);               if (wasGrounded != m_Grounded && m_Grounded == true)             {                 audioManger.PlaySound(landingSoundName);             }               // Set the vertical animation             m_Anim.SetFloat("vSpeed", m_Rigidbody2D.velocity.y);         }           public void Move(float move, bool crouch, bool jump)           {             // If crouching, check to see if the character can stand up             if (!crouch && m_Anim.GetBool("Crouch"))             {                 // If the character has a ceiling preventing them from standing up, keep them crouching                 if (Physics2D.OverlapCircle(m_CeilingCheck.position, k_CeilingRadius, m_WhatIsGround))                 {                     crouch = true;                 }             }               // Set whether or not the character is crouching in the animator             m_Anim.SetBool("Crouch", crouch);               //only control the player if grounded or airControl is turned on             if (m_Grounded || m_AirControl)             {                 // Reduce the speed if crouching by the crouchSpeed multiplier                 move = (crouch ? move*m_CrouchSpeed : move);                   // The Speed animator parameter is set to the absolute value of the horizontal input.                 m_Anim.SetFloat("Speed", Mathf.Abs(move));                   // Move the character                 m_Rigidbody2D.velocity = new Vector2(move*PlayerStats.instance.movementSpeed, m_Rigidbody2D.velocity.y);                   // If the input is moving the player right and the player is facing left...                 if (move > 0 && !m_FacingRight)                 {                     // ... flip the player.                     Flip();                 }                     // Otherwise if the input is moving the player left and the player is facing right...                 else if (move < 0 && m_FacingRight)                 {                     // ... flip the player.                     Flip();                 }             }             // If the player should jump...             if (m_Grounded && jump && m_Anim.GetBool("Ground"))             {                 // Add a vertical force to the player.                 m_Grounded = false;                 m_Anim.SetBool("Ground", false);                 m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce));             }         }           private void Flip()         {             // Switch the way the player is labelled as facing.             m_FacingRight = !m_FacingRight;               // Multiply the player's x local scale by -1.             Vector3 theScale = playerGraphics.localScale;             theScale.x *= -1;             playerGraphics.localScale = theScale;         }     } }