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 /
avatar image
0
Question by N30N · Apr 09, 2015 at 05:48 AM · mobilejumpingplatformerclick

How to jump to platform by clicking on it

right now, I have my game set up intended for mobile. My character is the character controller. There is no gravity and no movement.

Character jumps to a platform when space bar is pressed and character automatically jumps at a fixed rate going from platform to platform. Platforms can't be skipped and players must jump through sequentially.

Instead of space bar, I want to figure out how i can click a specific platform and have the character go there to the platform I click. I want the platform that the player is supposed to jump on to be glowing and stop glowing afterwards.

If anyone can help me i would appreciate it :)

screenshot:

alt text

Test build here: https://www.dropbox.com/s/3qy39soj6lsdytc/Web.html?dl=0

This is what I have now for code:

 public class Jump : MonoBehaviour
 {
 
     CharacterController motor;
 
     public float maxJumpPower = 50; //Initial velocity for jump
     public float jumpPower = 0; // Current velocity for jump
 
     public float gravity = 0.75f;   //  Jump velocity reduced each frame
     public float maxFallSpeed = -20f;    //  Maximum velocity for fall- Limited to prevent falling through platforms
     bool isJumping = false; // Is the character jumping? Only move while jumping
     bool movingRight;   //  The character will move to the right or to the left only
 
     public float maxRunSpeed = 5;   //  The character will have its speed set to this if it is moving right, or this * -1 to move left
     float runSpeed = 10f; // Current speed
 
     void Start()
     {
         //  Get the CharacterController attached to the gameObject that this script is attached to
         motor = gameObject.GetComponent<CharacterController>();
     }
 
     void Update()
     {
         //  if the character is on the ground, he must not be jumping
         if (motor.isGrounded)
         {
             isJumping = false;
         }
 
         // if the character isn't jumping and they press jump, start them at full speed
         if (Input.GetKeyDown(KeyCode.Space) && isJumping == false)
         {
             isJumping = true;
             movingRight = !movingRight;
             jumpPower = maxJumpPower;
         }
 
         //  reduce jump velocity by gravity every frame
         jumpPower -= gravity;
         if (jumpPower < maxFallSpeed)
         {
             jumpPower = maxFallSpeed;
         }
 
 
         // Set the proper speed for moving right or left
         if (movingRight)
         {
             runSpeed = maxRunSpeed;
         }
         else
         {
             runSpeed = -maxRunSpeed;
         }
 
         //  If the character is jumping, move it. X is horizontal, and Y is vertical
         if (isJumping == true)
         {
             Vector3 moveVector;
 
             moveVector = new Vector3(runSpeed * Time.deltaTime, jumpPower * Time.deltaTime, 0);
 
             motor.Move(moveVector);
         }
 
     }
 }


capture.png (5.4 kB)
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
1

Answer by Veldars · Apr 09, 2015 at 06:08 AM

For me the shorter way to do that is firstly to create a script implementing OnMouseDown function. After that you can attach this script to each platform and easily call a function from Your game controller when a platform is clicked.

 public class PlatformController: MonoBehaviour
 {
   // The jump script
   private Jump  _jump;
 
   void Start() {
     // Find in the scene the jump script.
     _jump = GameObject.FindGameObjectWithTag("JumpEmptyGameObject").GetComponent< Jump >();
   }
 
   void OnMouseDown () {
     // call your function witch will make glowing the platform and make jump...
     _jump.jumpFunction(this);
   }
 
 }

I hope this help...

Comment
Add comment · Show 4 · 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 N30N · Apr 09, 2015 at 08:12 PM 0
Share

what's the "jumpFuction()" on line 13?

avatar image Veldars · Apr 10, 2015 at 06:18 AM 0
Share

Your own built function ^^. In your Jump class you can create a public function (jumpFunction) and send it the selected platform (this) ... After that I think you already have done most of the work.

avatar image N30N · Apr 10, 2015 at 06:23 AM 0
Share

how do i make it jump the specific amount of distance? in my code, i have an x and y force i can control and tweak but i can't turn it into a seperate function because the character will freeze in the air and i will have to hit jump button every frame.

avatar image Veldars · Apr 10, 2015 at 08:10 AM 0
Share
 private Vector3 _platformDistance;
 
 public void jumpFunction(GameObject platform) {
 
   isJumping = true;
   _platformDistance = platform.transform.position - motor.transform.position;  // I assum that motor is your player...
 
 }
 
 and you have your X and Y (_platformDistance.x && _platformDistance.y)

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

auto jumping to a platform 0 Answers

how to flip a sprite 0 Answers

2D Sidescroller enemy AI jump help! Picture Included! 3 Answers

Platformer cat not jumping and is flinging across the map when hitting a corner 2 Answers

Input Axis Vertical is not set up? 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