- Home /
How to to not move when shooting?
Hey guys,
So I am moving my player forward throughout the game, user cannot change this. I have implemented two CnControl buttons, which on Tap, shoot.
However, whenever I tap the button, the player in-game seems to move just a bit: it looks like a really short laggy move to the direction where the button is in canvas.
My PlayerMovement.cs
   void FixedUpdate ()
         {
             transform.Translate(Vector3.forward * forwardSpeed * Time.fixedDeltaTime, Space.Self);
 
             Vector3 deltaPosition = transform.forward * forwardSpeed;
 
 
             if (Input.touchCount > 0) {
                 if (!CnInputManager.GetButton ("Jump")) {
                     
                     Vector3 touchPosition = Input.GetTouch (0).position;
                     if (touchPosition.x > Screen.width * 0.5f)
                         deltaPosition += transform.right * sideSpeed;
                     else
                         deltaPosition -= transform.right * sideSpeed;
 
                     transform.position += deltaPosition * Time.deltaTime ;
                 }
 
             }
My ShootingScripts.cs
 IEnumerator FireLaser() {
     laserBeam.enabled = true;
     flare.enabled = true;
     //audio.Play ();
     while (CnInputManager.GetButton("Jump") && timer >= timeBetweenAttacks) {
         timer = 0f;
         laserBeam.material.mainTextureOffset = new Vector2 (0, Time.time);
         // Ray starts at GunTip and will go Forward from GunTip
         Ray ray = new Ray (transform.position, transform.forward);
         RaycastHit beamHit;
         // Setting the position of Beam, need two coordinates x,y
         laserBeam.SetPosition (0, ray.origin);
         // If the Ray hits something in 100 range
         if (Physics.Raycast (ray, out beamHit, laserRange)) {
             laserBeam.SetPosition (1, beamHit.point);
             if (beamHit.rigidbody) {
                 Debug.Log ("Bear hit");
                 // Apply 5 times force at the point we are hitting enemy
                 beamHit.rigidbody.AddForceAtPosition (transform.forward * appliedForce, beamHit.point);
             }
         } else {
             // This will be a ray 100 units forward
             laserBeam.SetPosition (1, ray.GetPoint (laserRange));
     
         }
         yield return null;
     }
     laserBeam.enabled = false;
     //laserBeam.SetVertexCount (0);
     flare.enabled = false;
     //audio.Stop ();
 }
I am not sure what I am doing wrong, but based on the behaviour I can examine, I assume that whenever I touch the Button, the game thinks I want to move to that direction, however, in PlayerMovement script, I am trying to isolate the onButtonPress with an if statement.. so I don't know why it's get triggered anyway.
I think the answer to those will also solve my Shooting while Movement left or right, because similar behaviour appears - the player is moving like it lags / freezes every second.
Any help appreciated.
Your answer
 
 
             Follow this Question
Related Questions
How : Player move forward automatically (global Z axis) & 'not' the direction it's facing 3 Answers
I Want To Shoot Bullets Correctly. 2 Answers
Photon Player Controls Other Player 0 Answers
How do I make a 3D character move and rotate (turn) the same direction they move? c# 0 Answers
Shooting problem Unity3D C# 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                