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 carter-carl30 · May 28, 2012 at 10:25 PM · androidjavascriptjumpballtouchpad

android, roll a ball, using single touchpad to jump

Hi, I am having a go at creating a small game. I am using the roll a ball prefab in a small boxed area with a couple of ramps and platforms.

I have this working fine when i tilt the device the ball rolls around perfect.

what I want to know is: I have added the single touchpad prefab (from standard mobile assets) to the right hand side of my screen, when I build the game and press it I can see that it is recognising the touch.

Is it possible to add a script to the touchpad or to my roll a ball prefab to make the ball jump in the air such as:

rigidbody.AddForce (Vector3.up * 10);

when the touchpad is touched? without messing up the roll a ball controls?

any help, suggestions, clues appreciated! :)

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 carter-carl30 · Jun 06, 2012 at 06:46 PM 0
Share

anyone please help?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Tim-Michels · Jun 29, 2012 at 09:55 AM

Well, the moment you touch you should indeed do: rigidbody.AddForce(Vector3.up 10, ForceMode.Impulse);*

The ForceMode.Impulse is something I always use for jumping. I don't exactly know what you're trying to achieve, do you want to change the existing script of the touchpad, or do you want to write your own script?

I will basically give you an example of using the simple MouseDown function in a seperate script. You will need to create a new script, for example JumpOnTouch.

In this script, this is what the update should look like:

 void Update()
     {
         if (Input.GetMouseButtonDown(0))
         {
             rigidbody.AddForce(Vector3.up * 10, ForceMode.Impulse);
         }
     }

This script should be added to your ball, which has the rigidbody attached. With this code your ball will jump when you press the screen. I would also change the parameter Vector3.up 10 to Vector3.up force, where force can be a public variable to adjust the force of your jump.

If you want to limit the position where you should click to jump, you can just use the Input.mousePosition to write some extra checks for where the player clicks.

You should perhaps also check if your player is grounded in order to jump. (check raycasting)

I hope this helps you on your way.

Cheers ;)

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 carter-carl30 · Jun 29, 2012 at 09:30 PM 0
Share

@Tim $$anonymous$$ichels, Thankyou mate! that works perfectly :))

to make force a public var would I do it like this?:

var force : float(0);

??

i'm using javascript

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

Move forward and jump using touchpad 0 Answers

Make a ball jump on plane collision 1 Answer

Add tilt function to rotate a ball android device 0 Answers

Desperate for help on control for a ball on android phone. 1 Answer

Jumping script OnCollisionStay didn't work 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