Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 WyvernWats · Mar 25, 2021 at 02:48 AM · scripting problemphysics

trouble making a fast projectile

Hi everyone, I made a bullet using linecast in a 2.5D space shooter game, however it has a problem when the collider hits the bullet before the bullet hits the collider, so the linecast ignores the collider from the starting point and finally does not collide.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class BulletScript : MonoBehaviour
 {
     public WeaponScript Owner;
     [HideInInspector]
     public Vector2 FireSpot;
     public string Team;
     [HideInInspector]
     public Vector2 LastPosition;
 
     public float BulletSpeed;
     public float Pierce;
 
     void Start()
     {
         LastPosition = transform.position;
     }
 
     void Update()
     {
         transform.Translate(FireSpot * BulletSpeed * Time.deltaTime);
         if (Physics.Linecast(LastPosition, transform.position, out RaycastHit HitInfo, LayerMask.GetMask("Hittable")))
         {
             Hit(HitInfo.collider, HitInfo.point);
         }
         LastPosition = transform.position;
     }
 
     // for subsequent hits
     public void PostHits(Vector2 Start)
     {
         if (Physics.Linecast(Start, end: transform.position, out RaycastHit HitInfo, LayerMask.GetMask("Hittable")))
         {
             Hit(HitInfo.collider, HitInfo.point);
         }
     }
 
     public virtual void Hit(Collider other, Vector2 Point)
     {
         if (other.GetComponent<RPGBasicScript>())
         {
             if (other.GetComponent<RPGBasicScript>().Team != Team)
             {
                // { damage calculations }
 
                 if (Pierce > 0)
                 {
                     Pierce--;
                     PostHits(Point);
                 }
                 else
                 {
                     Destroy(gameObject);
                 }
             }
         }
     }
 }

alt text

I need a faster projectile that the rigidbody supports and that penetrates enemies, I tried to change the order of the scripts but without success, thanks to all.

bug.png (95.9 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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by CiberX15 · Mar 25, 2021 at 03:09 AM

When you say you need a faster projectile than rigidbody supports do you mean you are hitting physics tunneling errors? (Object is moving so fast that it can travel the entire distance of an object in a frame and thus not be in collision with it even though its path took it through the object?)

If that's the case you might try setting your Rigidbody Collision Detection mode to Continuous Dynamic (or if you are using a kinematic rigidbody use Continuous Speculative). These collision modes are more expensive which is why they do not default, but they account for the tunneling problem. still counting a collision at the correct point even with fast-moving colliders.

Then you could just use OnCollisionEnter to detect the collision.

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 WyvernWats · Mar 25, 2021 at 03:46 AM

I just tested using OnTriggerEnter with Continuous Dynamic on the bullet and on the enemy, but above 100 speed the bullet ignored some enemies on the way hitting the last one without hitting the first one.

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

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

267 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

My raycast wont function properly 0 Answers

Script adds rigidbody but player can walk straight through the gameobject? 1 Answer

Different bullet effect on different physics materals. 1 Answer

Rotating a rigidbody using AddTorque, need help!!! 1 Answer

Custom Character Controller Errors? 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