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 Fr0stbite · Jun 15, 2013 at 11:18 AM · collisionrigidbodycollider

How to speed up?

I made a bow what shot an arrow and i want to the arrow stop when collision with a wall the arrow's script is now:

 #pragma strict
 
 function Start () {
 
 }
 
 function Update () {
 
 }
 function OnTriggerEnter (other : Collider) {
         rigidbody.isKinematic = true; 
     }

but sometimes its move through the walls and stop in the middle of the room in the air. Help me please Sorry for my bad english :)

Comment
Add comment · Show 3
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 Eugenius · Jun 15, 2013 at 12:12 PM 0
Share

And what is the piece of code you've used to actually move the arrow? The code above does not offer much info to go about.

avatar image Fr0stbite · Jun 15, 2013 at 05:13 PM 0
Share
 function Fire()
 {
    animation.Play("PullAnim");
    BulletSpeed += 100;
    if(BulletSpeed == 5000){
     animation.Play("FireAnim");
    var Bullet1 : Rigidbody = Instantiate(Bullet, Spawn.position, Spawn.rotation);
    Bullet1.AddForce(transform.forward *BulletSpeed);
    BulletSpeed = 0;
    CanFire = false;
    Ammo -= 1;
    yield WaitForSeconds(0.1);
    CanFire = true;
    BulletSpeed = 0;
    
    } 
     
      
    
 }
avatar image Eugenius · Jun 15, 2013 at 05:18 PM 0
Share

So when you shoot, your bullets' speed is 100 but it doesn't do anything. When the speed of the bullet is 5000 you instantiate a bullet rigidbody and add force to it but you set your bulletspeed back to 0, twice. Shouldn't the bullet speed remain constant until colliding? Therefore when it reaches the wall it will stop moving?

3 Replies

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

Answer by robertbu · Jun 15, 2013 at 02:13 PM

Getting something to stop immediately turns out to be a somewhat hard problem, and I could only come up with a couple hackish solutions. The immediate issue may be solved by reducing the Fixed Timestep. From the edit menu, select Project Settings/Time. Reduce the Fixed Timestep from 0.02 to 0.01. As for other movement see this answer:

http://answers.unity3d.com/questions/462907/how-do-i-stop-a-projectile-cold-when-colliding-wit.html

Comment
Add comment · Show 3 · 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 Eugenius · Jun 15, 2013 at 05:01 PM 0
Share

Good solution!

Although, wouldn't it be easier for him to create a new speed variable which he could set to 0 at any time he would like the object(arrow in this case) to stop?

^_^

avatar image Fr0stbite · Jun 15, 2013 at 05:22 PM 0
Share

thx i changed the reduced steps to 0.01 and its works

avatar image robertbu · Jun 15, 2013 at 07:16 PM 0
Share

@Eugenius - unfortunately setting Velocity to 0 at the time OnCollisionEnter is called does not instantly stop the object. There appears to be a single frame of update.

avatar image
0

Answer by PAHeartBeat · Jun 15, 2013 at 12:20 PM

Just use Collider on your wall and don't use isTrigger Property as true. if you translating object by code, it will not stop in some cases, use rigidbody and apply force to your bow

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 Soumya · Jun 15, 2013 at 01:47 PM

Go to the arrow prefab and uncheck "Trigger".

Then , change

 function OnTriggerEnter (other : Collider) {
     rigidbody.isKinematic = true; 
 }

to

 function OnCollisionEnter () {
     rigidbody.isKinematic = true;
 }


Also, if your arrow moves at a high speed , it will sometimes not detect collisions. Hope I helped :)

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 Fr0stbite · Jun 15, 2013 at 03:01 PM 0
Share

the same problem :(

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

17 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

Related Questions

Collider going through walls with box collider.. 1 Answer

Rigidbody colliders 1 Answer

My Character controller is being push a little bit when i'm about the get the coins. How can i possibly detect collision and destroy the coins without actually getting affected by the colliding physics? 1 Answer

Objects with colliders going through walls and each other. 3 Answers

GameObject ignores collision while swinging from hinge joint 2D 4 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