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 TakMarche · Aug 10, 2012 at 11:53 AM · colliderontriggerentermesh colliderbox collider

Mesh Collider Won't Work After Running Another Collider

I really don't know any other way to explain this but here's whats happening. I'm working on a 2D Space Shooter and my spaceship/spacecraft works fine when it set to a box collider. I'm able to generate the shield and everything and when the shield get's destroyed (after 3 collisions from an enemy object) this spaceship continues to get hit...

However my problem is,

Changing the spaceship from box collider to mesh collider (to make it more fair because the ship isn't a square and it can get hit before actually being touched) everything works fine until the shield get destroyed. After the shield is gone the enemies just passes through my ship. I'll post up my three scripts if it can help. (I did not paste the full code due to making it such a long post, instead I posted the parts I'm trying to figure out or what is being used)

         // Player Script

public int numberOfShields = 3; // Set the number of shields our player gets to use public GameObject shieldMesh; // Load shield mesh public bool shieldOn =false;

void Update () { // Store input variables float transV = Input.GetAxis("Vertical") playerSpeedVertical Time.deltaTime; // Use to store vertical movement float transH = Input.GetAxis("Horizontal") playerSpeedHorizontal Time.deltaTime; // Use to store horizonal movement

// Move player based on input transform.Translate(transH, transV, 0); // X to move left and right. Y to move up and down

// Create a bullet if(Input.GetKeyDown("space")) { if (DefaultShot == true) { Instantiate(projectile, socketProjectileDefault.position, socketProjectileDefault.rotation); audio.Play(); } }

// Create a sheild if (Input.GetKeyDown(shieldKeyInput)) { if (shieldOn == false) { GameObject clone = Instantiate(shieldMesh, transform.position, transform.rotation) as GameObject; clone.transform.parent = gameObject.transform; shieldOn = true; } }

// Shield Script

  public int shieldStrength = 3;
 

void Update () {

if (shieldStrength <= 0) { Destroy(gameObject); } }

// Enemy Script

void OnTriggerEnter (Collider other) { if (other.gameObject.tag == "Player") { scriptPlayer playerScript = other.GetComponent(); playerScript.lives -= 1; playerScript.DoubleShot = false; playerScript.DefaultShot = true;

// Tell scene manager that we lost a life scriptSceneManager sceneScript = sceneManager.GetComponent(); sceneScript.SubtractLife();

if (explosion) { Instantiate(explosion, transform.position, transform.rotation); audio.clip = playerDamageAudio; audio.Play(); }

StartCoroutine(playerScript.PlayerDamage()); ResetEnermy(); }

if (other.gameObject.tag == "Shield") {

scriptShield shieldScript = other.GetComponent(); shieldScript.shieldStrength -= 1;

if (explosion) { Instantiate(explosion, transform.position, transform.rotation); audio.clip = shieldExplosionAudio; audio.Play(); }

ResetEnermy(); }

if (explosion) { RandomSpeedAndSize(); }

}

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
0
Best Answer

Answer by RodrigoSeVeN · Aug 10, 2012 at 02:26 PM

You could stick to what is working, and adapt it.

These games normally have smaller collision boxes, as if cutting a small piece of the wings, to be fair to the player in the same manner you said. You get to keep your working mechanics, and will not lose anything just because you don't have mesh precision colision. You could set the mesh collider to convex to see if you like the results and if it works like the box.

Also, you never use meshs that are too complex for collision. You make a raw shape mesh to use for collision instead. In case using a smaller box is not good enough, try moddeling a simpler mesh, as this don't seen to be a code problem(mesh collider is not as reliable as the other simples types of collider).

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 TakMarche · Aug 10, 2012 at 07:24 PM 1
Share

Thank you for the answer, I tried what you said with the convex and it didn't work so I ended up sticking with what I had and just added another shape collider to fit the size of the ship.

avatar image
0

Answer by GamersFrenzy · Jul 15, 2014 at 04:10 AM

Not the script, add Rigidbody to both the Player and the Trigger Collider and check kinematic on both I also set Collision Detection to continuous That should help out.

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

9 People are following this question.

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

Related Questions

For flat mesh, is there a performance difference between box vs mesh colliders? 1 Answer

How to use different and distinguish between different box colliders? 1 Answer

OnTriggerEnter works, OnTriggerExit doesn't 3 Answers

SOLVED - Assign mesh collider to fit 3d Text perfectly 1 Answer

How to make gameObject make only one collision 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