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 $$anonymous$$ · Aug 18, 2013 at 03:44 AM · rigidbodyprojectiles

How Can I Make a Projectile Move?

I've tried Rigidbodies but I can't seem to get them to work, as they show up for a second (Not literal), and then disappear. When I look at the properties, they get very, very far away. If it helps, I am trying to make a bow fire an "arrow".

 #pragma strict
 
 function Start () {
 
 }
 
 function Update () {
     if (Input.GetMouseButtonDown(1)) {
         var projectile : GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
         projectile.transform.position = transform.position;
         projectile.transform.rotation = transform.rotation;
         projectile.transform.localScale = Vector3(0.1, 0.1, 1);
         projectile.gameObject.AddComponent(Rigidbody);
         projectile.rigidbody.useGravity = false;
         projectile.rigidbody.AddForce(Vector3.forward * 1000);
     }
 }
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

Answer by Linus · Aug 18, 2013 at 03:53 AM

You should use AddForce not change the drag.

The way you have set it up, force will only be added once, on the frame it was created.

AddForce needs to be constantly added to the object. Make a new script and attach it to the object.

CubeScript.js

 //Sample from the documentation
     // Adds a force upwards in the global coordinate system
 
     function FixedUpdate () {
         rigidbody.AddForce (Vector3.up * 10);
     } 



http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddForce.html

 function Update () {
 if (Input.GetMouseButtonDown(1)) {
 var projectile : GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
 projectile.transform.position = transform.position;
 projectile.transform.rotation = transform.rotation;
 projectile.transform.localScale = Vector3(0.1, 0.1, 1);
 projectile.AddComponent(Rigidbody);
 projectile.rigidbody.useGravity = false;

 projectile.AddComponent(CubeScript);
 }
 }

Also, make it a habit to leave out the "" when getting or adding components `projectile.gameObject.AddComponent(Rigidbody);

You are learning that is great, but watch/read some tutorials, we are not always gonna be there to hold your hand while your learning.

The forum would be a better place for these questions as well.

Plenty of good ones on youtube and around the web.

(I have no intention of being rude)

Comment
Add comment · Show 6 · 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 $$anonymous$$ · Aug 18, 2013 at 03:55 AM 0
Share

I actually tried that and it did the same thing. The drag was an attempt to make it stop moving.

avatar image Linus · Aug 18, 2013 at 04:06 AM 0
Share

Updated my answer.

avatar image $$anonymous$$ · Aug 18, 2013 at 04:12 AM 0
Share

For whatever reason, it still doesn't seem to work. I did edit it so that it'd move forward rather than up, but the Y coordinate still rises the most.

avatar image Linus · Aug 18, 2013 at 04:19 AM 0
Share

aha, gravity is enabled by default. It needs to be turned off. Updated answer again

avatar image $$anonymous$$ · Aug 19, 2013 at 07:56 PM 0
Share

Still doesn't want to work the way I really want it to.

Show more comments
avatar image
0

Answer by robertbu · Aug 18, 2013 at 05:52 AM

The only problem I see in your script is line 8. While adding force each frame as @Linus suggests is not a bad idea (especially when mimicking something like a missile), it is not necessary. Most projectiles like bullets do it like you do with a single application of force. Line 8 should be:

 projectile.rigidbody.Addforce(transform.forward * 1000);

Also line 7 can simplified to:

 projectile.AddComponent(Rigidbody);

...since projectile is a game object.

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

15 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

Related Questions

Firing Rocket From A Car 0 Answers

Collisions not being detected at certain distance 1 Answer

How to fire projectile in direction character is facing? 3 Answers

Why are my projectiles facing the wrong way? 1 Answer

Simulating wheels without a wheel collider? 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