Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Dminic981 · Jun 17, 2020 at 09:45 AM · shootingnewbieoffsettop down shooterrotation detection

Rotation offset after hitting wall, help please,Rotating towards mouse unwanted offset after colliding with any wall in 3D

Hello, i hope someone can help me with this as i have not found a solution after trying to find one for about two hours. I'm trying to make a top-down shooter in 3D. So far i got everything working except this breaks the whole game: alt text

alt text

This is the code responsible for rotating towards the mouse in 3D space, shooting, player movement and also crosshair placement:

         crosshair = GameObject.Find("Crosshair").GetComponent<RawImage>();
         rb = GameObject.Find("Player").GetComponent<Rigidbody>();
         plr = GameObject.Find("Player").GetComponent<Transform>();
     }
 
     private void Update()
     {
         if (playerLives <= 0)
         {
             Time.timeScale = 0f;
             SceneManager.LoadScene(0);
             Time.timeScale = 1f;
         } 
     }
 
 
 
 
     // Update is called once per frame
     void FixedUpdate()
     {
         hInput = Input.GetAxis("Horizontal") * 30f;
         vInput = Input.GetAxis("Vertical") * 30f;
 
         rb.AddForce(hInput, 0f, 0f);
         rb.AddForce(0f, 0f, vInput);
 
         if (Input.GetMouseButton(0) && Time.time >= nextTimeToFire)
         {
             nextTimeToFire = Time.time + 1f / 8f;
             GameObject nB = Instantiate(bullet, plr.transform.position, plr.transform.rotation);
             nB.transform.Translate(0f, 0f, +.6f);
             nB.GetComponent<Rigidbody>().velocity = nB.transform.forward * 40f;
         }
 
         Ray cameraRay = Camera.main.ScreenPointToRay(Input.mousePosition);
         Plane groundPlane = new Plane(Vector3.up/5, Vector3.zero);
         
 
         if (groundPlane.Raycast(cameraRay, out rayLength))
         {
             Vector3 pointToLook = cameraRay.GetPoint(rayLength);
             plr.LookAt(new Vector3(pointToLook.x, plr.position.y, pointToLook.z));
         }
 
         crosshair.transform.position = Input.mousePosition;
 

I think I know what's wrong, the player object gets rotated a little bit because of the collision I just don't know how to reverse/prohibit that rotation. Sorry for the huge post. Thanks in advance!

before.png (39.6 kB)
after.png (60.1 kB)
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

133 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Shooting projectiles in a 2d top down shooter with multiplayer 1 Answer

3D top down shooter mouse follow inaccurate. 0 Answers

Problem with a charged projectile direction 1 Answer

How to shoot using the right mobile Joystick? 2 Answers

[C#]Instantiate projectile a distance away from Player 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