Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by David92 · Jan 19, 2017 at 09:34 AM · unity 5movement3dshooting

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges