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 Zach28 · Nov 06, 2015 at 04:41 PM · c#physics2d

How to smash a ball? 2D (C#)

Hello, sorry I'm new in programming. But I would like to make a simple game, baseball game-like. I would like to smash the ball (2D) to make it fly. But my bat is not even smashing the ball, it's just pushing it away :( pleaaase help. Any help is really appreciated :D Thank you in advance :D.

     public float RotSpeed = 5.0f;
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
             
         if(Input.GetKey(KeyCode.D)) {
             transform.Rotate(0, 0, RotSpeed * -1); 
         }
         
         if(Input.GetKey(KeyCode.A)) {
             transform.Rotate(0, 0, RotSpeed);
         }
     }
 }
 `
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 Scribe · Nov 06, 2015 at 06:40 PM 0
Share

decrease the mass of the ball, and increase the mass of the bat, it should increase the effect of hitting it

avatar image Zach28 Scribe · Nov 07, 2015 at 07:39 AM 0
Share

Thank you :D but it didn't work :(

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Dibbie · Nov 06, 2015 at 05:47 PM

In my personal opinion, anything with physics, especially starting out, can be advanced. Look into RigidBody2d, and Collider2D (Im not sure if you are using a BoxCollider2d, or a SphereCollider2D or another type of Collider2d).

The reason I say to look into these, is because it can be hard to explain the entire process to fixing your problem especially without actually seeing exactly how your physics are reacting, the code doesnt help very much at all, because it only shows how your rotating an object, that doesnt even seem like it may have any reference to any physics.

RigidBodies contain weight, as well as gravity settings, the project itself may even have settings, and you can add stuff like physics materials which can do some pretty interesting stuff (in my opinion), like have whatever object bounce off of another, or slide off another, or react like it would if it hit wood or ice, or you can even set up your own. It can get complicated, cause Physics in general, can get complicated. So for sure look into those 2 elements.

For starting out, you may want to consider maybe trying a more simplistic project, or if you are really passionate about this one, maybe look on YouTube for some tutorials on Physics and how they work in Unity, and try to replicate them, to get a understanding of it.

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 Zach28 · Nov 07, 2015 at 07:14 AM 0
Share

Thank you sir :D I already watched many unity and program$$anonymous$$g tutorials on youtube, but really can't find anything. I was looking for a scripting tutorial that spins an object using force. Because I think, if I used force in rotating it, it would be able to smash the ball. Because i think, using transform.Rotate is just teleporting the plank's rotation :o Thank you sir :D

avatar image Dibbie Zach28 · Nov 08, 2015 at 05:28 PM 0
Share

Youll probably see some problems using force, cause its continuous and I found accumulative if you donno how to use it right - for rotating, maybe look into Slerp. Itll allow you to rotate an object over time.

avatar image Zach28 Dibbie · Nov 10, 2015 at 10:30 AM 0
Share

Thank you sir :D Noted :D

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to learn loading/pressure/compression on a 2D body? 0 Answers

Physics2D.OverlapBox (C#) 0 Answers

How can I isolate just the character to slow down 0 Answers

My character flies upwards instead of jumping (2D) 1 Answer

Is calling OnCollisionEnter2D on allot of GameObjects leading to worse performance? 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