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
0
Question by Chiraag26 · Sep 05, 2018 at 03:55 PM · movementclick to move

How to click on ball to release?,Click on ball to release

Hello, I am creating a basic bowling game. When I play the game, the ball automatically gets released towards the pins. What script do I need to first move the ball (left or right arrows keys) and then click on the ball to release? Thanks. Please see below code I already have for forward movement

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class BallMovement : MonoBehaviour { public Rigidbody rb;

 public float forwardForce = 100f;

 void FixedUpdate()
 {
     rb.AddForce(0, 0, forwardForce * Time.deltaTime);
 }

},Hello. I am making a basic bowling game and I want to know how to click on the ball so it releases and hits the pins. I have added some code (see below) for force forward movement. However, when I play the game the ball releases automatically. I want to adjust the ball first (left/right arrow keys) and then click on the ball to release for it to hit the pins.

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class BallMovement : MonoBehaviour { public Rigidbody rb;

 public float forwardForce = 100f;

 void FixedUpdate()
 {
     rb.AddForce(0, 0, forwardForce * Time.deltaTime);
 }

}

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 _Venus_ · Sep 05, 2018 at 05:15 PM

You can try handling it differently. For example: using System.Collections; using System.Collections.Generic; using UnityEngine; public class BallMovement : MonoBehaviour { public Rigidbody rb; public bool leftnright; public float forwardForce = 100f; public float leftForce; void FixedUpdate() { if(leftnright) { if(Input.GetKey(KeyCode.A)) { transform.postion.x *= leftforce; } if(Input.GetKey(KeyCode.D)) { transform.postion.x *= -leftforce; } if(Input.GetButtonDown("Fire1")) { leftnright = false; } } else if(!leftnright) { rb.AddForce(0, 0, forwardForce * Time.deltaTime); } } }

Please note that i havent tested this code yet, but i hope it can give you some insight.

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 Chiraag26 · Sep 06, 2018 at 10:15 AM 0
Share

@Venus Thank you for the help. I have changed the code to the above but there are errors on both "transform.postion.x *= leftforce" It shows a red line under position and leftforce. Is there any other simple code I can use?

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

141 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 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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Making a bubble level (not a game but work tool) 1 Answer

Player moves to the middle of the room when the level starts (2d point and click) 2 Answers

Objects move toward the center of the screen right after it is created 1 Answer

How do i make my chracter stop moving when the destination has been reached?,How do i prevent my character from moving when reached the destination 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