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 /
avatar image
1
Question by amiess · Dec 18, 2017 at 04:45 PM · vector3shootingballforward

Player doesn't shoot ball object forward like I tell him

Hello guys, here is the problem,

I am making a soccer game where a player can shoot a ball in front of him, just like in real soccer.

The problem is, when I shoot, the ball does not go straight forward like planned, but goes diagonnaly : at 5 (clockwise) when looking right, and at 7 when looking left. Here's a screenshot for better comprehension.

*green arrows : wanted direction *red arrows : actual and unwanted direction

alt text

Here is the code of the shoot function :

 void PassBall(float passCount)
     {
         ball.Pass(passCount * player.transform.forward);
         //passCount is an int variable that increments each a pass occures. It is used the define the power of the shot
     }

The function above is used in the playerController Script, when shot button pressed. It calls the following function, which is defined in the ball script :

    //Passes the ball
     public void Pass(Vector3 passForce)
     {
         if (!ballActive)
         {
             transform.parent = null;
             gameObject.AddComponent<Rigidbody>();
             Ball.GetComponent<Rigidbody>().AddForce(new Vector3(passForce.x * 5,passForce.y *5 + angle,passForce.z * 5), ForceMode.Impulse );
          } 
     }

I can't figure out what Im doing wrong, can u please bring some help ? Thanks in advance for ur attention.

capture.png (489.5 kB)
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 avinvij · Dec 18, 2017 at 05:00 PM 0
Share

In the Pass function where you are applying force, there is some angle added to y, is that making the difference?

avatar image amiess avinvij · Dec 18, 2017 at 05:23 PM 1
Share

Hi, the angle is something returned by another function that allows the player to aim his shot, this is why it is added to the y axis, it works well, and I tried removing it, same problem.

avatar image avinvij · Jan 19, 2018 at 11:54 AM 0
Share

Check with the value of player.transform.forward. Try to log it and check whether that is really the forward direction of the player.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by alphanike97 · Dec 18, 2017 at 05:41 PM

Hi! Why do you sums pass force + angle? AddForce(new Vector3(passForce.x * 5,passForce.y *5 + angle,passForce.z * 5), ForceMode.Impulse ); Check if the Line Code was Right

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 amiess · Dec 18, 2017 at 05:56 PM 1
Share

Angle is returned by another function to let the player aim his shot. It works fine, but in order to check if it was the problem, I tried removing it, but the problem was still there.

avatar image kevinforrestconnors · Dec 18, 2017 at 07:02 PM 1
Share

Probably to make the ball rise in the air.

avatar image
0

Answer by jawadahmeddogar · Jan 19, 2018 at 04:30 PM

try to uncheck gravity on ball's rigidbody component and then see what happens.

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

92 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

Related Questions

transform.forward makes my GameObject Disappear 0 Answers

2D Shooter - shooting forward at the current rotation 2 Answers

raycast is pointing in two directions? 1 Answer

What is the error? 2 Answers

Using Vector3 with multiple directions 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