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
1
Question by SMH17 · Jun 19, 2015 at 06:32 PM · unity 5physicsshootingprojectile

Cannon shoots in wrong direction with unrealisic Physic

I want to implement a realistic cannon shoot but the cannon balls are fired in wrong direction and seems like soap bubble despite metal material and my weight settings

Here a sample video of the result LINK

My intention is to shoot in the direction of the boat in position (-7,10.4,100).

The cannon is in the position (0, 10.39,-40)

Here the code to fire:

 var Bullet_Active: Transform;
 var bullet_energy=999;
 
 function Start () {
 
 }
 
 function Update () {
     if(Input.GetKey("space")){CannonFire(); }
 }
 
 function CannonFire () {
     var bullet_istance :Transform;
     bullet_istance=Instantiate(Bullet_Active, transform.position, transform.rotation);
     bullet_istance.GetComponent.<Rigidbody>().AddForce(bullet_istance.transform.forward*bullet_energy);
 }


Comment
Add comment · Show 2
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 OctoMan · Jun 19, 2015 at 08:38 PM 0
Share

Looks like a collider Problem. You need to disable collision bullets with bullets.

  • First change the collider of the bullet to IsTrigger and test again

  • If that is not what you want go to the physicsmanager and change the $$anonymous$$atrix to your needs, So make Bullets in a Bullet Layer and Disable each other (Edit > Project Settings > Physics)

Also limit how many bullets are instantiated.

avatar image SMH17 · Jun 20, 2015 at 05:07 PM 0
Share

the problem was in direction transform.forward. The right direction is transform.up in my case

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by screenname_taken · Jun 19, 2015 at 09:42 PM

You are shooting all the balls together at the same exact time and they are colliding with each other. Instead make a layer specific for the balls that is able to interact with everything but the balls, so that they won't interfere with each other. Then also make a script that has the balls in an array and implement a delay so that they won't shoot like pellets from a shootgun, but instead one ofter the other. They are shooting together because you have the check in the update loop, with no cooldown.

Put a boolean in the firing function that goes false the moment it's called and then back to true after some time and check that with an if statement to see if you should shoot, so that the balls will go "boom .... wait ... boom" instead of "splat".

Oh and try not to instantiate stuff, it takes cpu time. Instead have a bunch of them already in the scene the time it loads, but just disabled, and place them in an array. That way the system will just pick a free one, enable it, shoot it, and once it hits and does the damage you can disable it and make it available again.

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 SMH17 · Jun 19, 2015 at 09:51 PM 0
Share

Thanks for the answer however the main error was in direction transform.forward. I must use transform.up.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Projectile Hit Detection with Bullet Drop 1 Answer

bullet realistic penetration 0 Answers

Calculating trajectory of elliptical orbit? 2 Answers

Calculating a projectiles angle required to hit object. 2 Answers

Similar movement to a game (look description) 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