Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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
-1
Question by anant6 · Aug 23, 2019 at 09:08 AM · physicsbulletbug-perhapslinecaststrange

Something Really Strange

Hey guys i am making a tps multiplayer game in unity.this is my first game in unity and overall so the problem is really simple and weird. i put this piece of code in my ammo script:-

private void FixedUpdate() { if (ammoType=="RealTime") {

             transform.Translate(Vector3.forward * speed * Time.deltaTime);
             if (Physics.Linecast(lastPosition, transform.position, out target,0,QueryTriggerInteraction.Ignore))
             {
                 Debug.Log(target.transform.gameObject.name);
                 transform.position = target.point;
                 Instantiate(hitEffect, target.point, Quaternion.identity);
                 Debug.Log("Inst hit effect realtime");
                 Destroy(gameObject);
             }
             
         }
        
     }
     private void LateUpdate()
     {
         lastPosition = transform.position;
         

     }

The purpose of this code is to avoid bullet through paper problem. So regardless of its speed projectile always knows when it collide with something. This code was working perfectly till yesterday, than suddenly it stopped working. im stuck with it and in all my life im unable to figure out what happened suddenly. any help regarding this would be greatly 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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by anant6 · Aug 23, 2019 at 04:08 PM

@Danzou
1. I reset all the physics settings to default and it still doesn't work 2. Only projectiles are triggers that is the reason i chose to ignore triggers during the linecast 3. tried and it still doesnt work.this is the new function:-

 private void FixedUpdate()
         {
             if (ammoType=="RealTime")
             {
                 transform.Translate(Vector3.forward * speed * Time.deltaTime);
                 Debug.Log("realtime");
                 Debug.DrawLine(lastPosition, transform.position,Color.blue);
                 if (Physics.Linecast(lastPosition, gameObject.transform.position, out target, 0, QueryTriggerInteraction.Ignore))
                 {
                     Debug.Log(target.transform.gameObject.name);
                     transform.position = target.point;
                     Instantiate(hitEffect, target.point, Quaternion.identity);
                     Debug.Log("Inst hit effect realtime");
                     Destroy(gameObject);
                 }
                
                 lastPosition = transform.position;
 
             }
            
         }
 

Please any help would be great as its making me insane

Comment
Add comment · Show 2 · Share
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
avatar image TurboHermit · Aug 23, 2019 at 08:20 PM 1
Share

I see that you have the layer$$anonymous$$ask parameter (after out target) from Linecast set to 0, try setting it to Physics.AllLayers or adding a variable Layer$$anonymous$$ask to your properties and manually set which layers you want to trigger on.

avatar image anant6 TurboHermit · Aug 24, 2019 at 08:55 AM 0
Share

yes sir it worked just fine on all changing 0 to physics.alllayers thank you so much!! thanks thanks thanks

avatar image
1

Answer by TurboHermit · Aug 23, 2019 at 11:47 AM

If you haven't changed anything in the code and it "suddenly" stopped working, it's very likely because something in the inspector or in settings have changed.

Since most of this is physics related, I suggest:

  1. Checking if you changed FixedUpdate rate in physics settings.

  2. The thing you're trying to hit is not a trigger, since you ignore querying triggers.

  3. Try setting "lastPosition" in the end of your FixedUpdate instead of LateUpdate. FixedUpdate triggers independently (at a fixed rate) from LateUpdate (every frame), so you're currently setting your lastPosition more often than checking for it, meaning this distance is not always equal to the distance you want it to check. I'm guessing this is your current problem, but that DOES mean that you've changed something in code.

Comment
Add comment · Share
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
avatar image
0

Answer by Parokonnyy · Aug 23, 2019 at 10:01 AM

Try to check what in the variable "ammoType". You can use Debug.Log(ammoType) or set the breakpoint on this line and debug to know the value. Probably, you accidentally change this variable in the code or in the inspector.

Comment
Add comment · Show 1 · Share
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
avatar image anant6 · Aug 23, 2019 at 10:52 AM 0
Share

@Parokonnyy No Sir ammoType is RealTime That's the reason projectile is travelling forward if it was "HitScan" Type Then it would instantly hit the target.It just isn't detecting any collisions

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

182 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 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

Multiple raycasts in same fixedupdate 3 Answers

How do I make certain parts of a mesh hide in runtime 1 Answer

Bullets spawn behind plane? 1 Answer

Aim helper in realistic sniper game 1 Answer

How to use linecast ?? 1 Answer


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