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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by MrPrajapat · Oct 27, 2013 at 03:15 PM · forcecurveprojectionfootballkick

Soccer: Control ball curve and projecton

Hello,

I am creating soccer based penalty shoot out game. I have no idea how can i add curve and accuracy factor in ball projection?

I have created simple projection towards goal post by adding force to ball.

Comment
Add comment · Show 1
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 robertbu · Oct 27, 2013 at 03:46 PM 0
Share

http://answers.unity3d.com/questions/377944/how-to-make-a-ball-rotate-as-per-its-moving-direct.html

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by cjdev · Oct 27, 2013 at 03:41 PM

An alternative to using a rigidbody would be to move the transform with a script. If you have a generalized equation you can just define whether the end position results in a goal or not. While there are many ways to get the positions along a curve, I'd personally use Bezier Curves to simulate the trajectory. Basically they're just a curve defined by a start and end point with two control points in the middle. I've recently been using Bezier curves and I use this script for them:

 using UnityEngine;
 using System.Collections;
 
 // This is a helper class to contain the four points and calculate the cubic function of a Bezier curve
 public class Bezier {
     public Vector3 A;
     public Vector3 B;
     public Vector3 C;
     public Vector3 D;
     float X;
     float Y;
     float Z;
     
     // The curve is defined by the four points which gives the basis for a cubic approximation
     public Bezier(Vector3 point1, Vector3 point2, Vector3 point3, Vector3 point4)
     {
         A = point1;
         B = point2;
         C = point3;
         D = point4;
     }
     
     // Returns the resulting position of the Bezier curve at time t, where 1 >= t >= 0
     public Vector3 GetPosition(float t)
     {
         float n = 1 - t;
         X = A.x*n*n*n + 3*B.x*n*n*t + 3*C.x*n*t*t + D.x*t*t*t;
         Y = A.y*n*n*n + 3*B.y*n*n*t + 3*C.y*n*t*t + D.y*t*t*t;
         Z = A.z*n*n*n + 3*B.z*n*n*t + 3*C.z*n*t*t + D.z*t*t*t;
         return new Vector3(X, Y, Z);
     }
 }

This class will let you get the position at a given percent of the curve. Using the ball as the first point, a point somewhere in front of the ball as the first control point, a point near the target destination as the second control, and finally, a target point, you should be able to get a curve that looks somewhat realistic and still gives you more precise control over the end position. Try playing around with four empty game object's transforms as the points to see what the curve looks like and if it works for you.

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

Answer by W1k3 · Oct 27, 2013 at 03:25 PM

I'm going to assume you are using instantiate with force to shoot the ball. So lets say force is applied to the Z axis, and you want to curve to the left. You could use rigidbody.AddForce(-2, 0, 0); to apply a small amount of force to left at the same time to give the illusion of curving.

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 MrPrajapat · Oct 27, 2013 at 03:40 PM 0
Share

Should i need to make seprate function for curve ball and what about accuracy?

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

19 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

Related Questions

script to add force to the ball in a football game! 1 Answer

The Script keeps executing..instead executing onec 0 Answers

Make a bowling ball spin on a swipe path 1 Answer

How can i make a ball jump in a curve from one place to another and vice versa. Like juggling a ball ! 0 Answers

Football Curl Shoot Logic and Approach on different swipe gesture? 2 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