Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by y11t_tr · Jan 08, 2017 at 07:01 PM · transformprojectiletranslateweapon

How to move a gameobject with a curve?

Hey there,

Lets say im tossing a hand grenade. So it would have a curved projectile and when it hits the ground its going to explode. This is how I shoot it:

 void Update () {
 if (Input.GetButton("Fire1"))
 {

     GameObject bomb= Instantiate(projectile, transform.position, transform.rotation);

 }
 }


And this is the script for bomb:

 void Update () {
 if (transform.position.y > 0)
 {
     transform.Translate(Vector3.forward * Time.deltaTime * 10);

 }
 else
 {

     Destroy(this); //explode here

 }
 }

The problem is the bombs goes straight forward right now.

How do make sure bomb goes in a curved path?

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 KoenigX3 · Jan 08, 2017 at 07:41 PM

You should add a Rigidbody component to the grenade prefab, and use the following code in the grenade script:

 void OnCollisionEnter(Collision collision)
 {
     Destroy(this.gameObject);
 }

And use the following code in the grenade launcher script:

 void Update () 
 {
     if (Input.GetButton("Fire1"))
     {
         GameObject bomb = (GameObject) Instantiate(projectile, transform.position, transform.rotation);
         bomb.GetComponent<Rigidbody>().AddForce(Vector3.forward * 200);
     }
 }

Rigidbody is a physics component which makes your gameobject behave like any normal objects - physics can affect them, which means they are aware of collision, gravity, and other forces. The first code will make sure that whenever the grenade collides with something, it will destroy itself (later on the explosion effect can be also written there, but be aware of the Destroy() function - if you implement the explosion effect with a Particle System attached to the grenade object, it will get destroyed on impact as well).

The shooter script gets the rigidbody component of the grenade, and applies force to it. Notice that you have to use bigger values than before.

Comment
Add comment · Show 2 · 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 y11t_tr · Jan 08, 2017 at 08:02 PM 0
Share

Tried this but bombs go directly bellow with this.

avatar image KoenigX3 y11t_tr · Jan 08, 2017 at 11:29 PM 0
Share

Try to increase the value of the force by changing 200 to a bigger value. If this does not help, check if the Vector3 points to the correct direction (you can also try Vector3.right, Vector3.up, and the negatives).

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

94 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Trying to move the Player 30 units on the x axis back and forth when clicking but transform.Translate not working reliably? 1 Answer

Smooth movement for a 3rd person camera 2 Answers

Move GameObject with transform.position 1 Answer

Position, left goes right and right goes left 0 Answers

Why does my weapon rotation change after hitting play? 0 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