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 Wettechsupport · May 10, 2013 at 10:11 PM · collision detectiontransform.positionistrigger

Trouble getting bullets to stop at solid blocks

I'm currently working on my first game (a 3D side scroller. It's a parody of Super Mario Bros) and until now I've been able to find answers via google searches, but now I've stumbled across a problem...

To avoid any nasty pushing-around physics, the bullets in my game (shirukens or fireballs, currently just shirukens) have a box collider and is set to a trigger, but no character controller. To move, it uses transform.position. Anyway, it collides with enemies and other triggers just fine, but when I try to hit a solid object (whether it be plane or cliff box), it doesn't process any of those collisions.

Code attached:

 #pragma strict
 
 private final var gravityRate : double = 25.0;
 private final var gravityMax : double = 100.0;
 private final var deathTimeMax : double = 0.5;
 private var gravity : double = 0.0;
 private var deathTime : double = 0.0;
 var direction : Vector3;
 var throwSound : AudioSource;
 var hitSound : AudioSource;
 
 
 function Start () {
     Debug.Log("Creating a g**d*** shiruken");
     throwSound.Play(0);
     
 }
 
 function Update () {
     if(deathTime > 0.0)
     {
         //Give the sound effect some time to work it's magic
         deathTime -= Time.deltaTime;
         
         if(deathTime <= 0.0)
         {
             deathTime = 0;
             Destroy(this.gameObject);
         }
         return;
     }
 
     
     gravity += gravityRate * Time.deltaTime;
     if(gravity > gravityMax)
         gravity = gravityMax;
         
     var offset : Vector3 = transform.position;
     offset.x += (direction.x * 30) * Time.deltaTime;
     offset.y += (direction.y * 15) * Time.deltaTime;
     offset.y -= gravity * Time.deltaTime;
     
     transform.position = offset;
     
 }
 
 function OnTriggerEnter(collision : Collider)
 {
     var other : GameObject = collision.gameObject;
     
     Debug.Log("OUCH!  " + other.tag);
     
     if(other.tag == "Enemy")
     {
         deathTime = deathTimeMax;
         hitSound.Play(0);
         var script : EnemyDamage = other.GetComponent(EnemyDamage);
         if(script != null)
             script.Damage();
     }
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MartinCA · May 11, 2013 at 12:30 AM

Do your projectiles or walls have rigidbodies? Collision and Trigger events will only raise when one of the objects has a rigidbody component.

You can view the collision and trigger event matrix here (scroll to the bottom): http://docs.unity3d.com/Documentation/Components/class-SphereCollider.html

Also, if you want to move rigidbodies, refer to this - http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.MovePosition.html

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

14 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

Related Questions

Rigidbody Precise Colliders 1 Answer

Jarring "snap" on 2d Camera raycast collider 0 Answers

My vehicle goes through walls and floors disregarding all colliders 2 Answers

C# Probability of Transform Colliding 1 Answer

Copying target's XY position to object's XY position 2 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