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 sadowlight123 · Jul 15, 2017 at 08:17 PM · jumpdistancemove

knowing maximum lenght a player can reach

Hello all , I am making a 2D endless runner game where platforms appear randomly ahead of player. These platforms can take random x and y positions and z=0. However , I need to write a formula that will enable me to let those platforms generate within the reach of the player. The code below describes the movement of the player. to move the player left and right , rigidbody.velocity was used. to move the player up , rigidbody.AddForce was used. A combination of both can let the player jump left or jump right My question is , how can I know what is the maximum lenght the player can reach ? This will help me set the maximum length between the platforms (in height and width). any extra explications or physics figures and schemes will be really much appreciated. Thank you for all in advance.

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

public class PlayerMovement : MonoBehaviour {

 public float MaxSpeed;
 private Rigidbody2D Rigid;


 public bool OnGround = false;
 public float CheckGroundRadius;
 public Transform GroundPoint;
 public float JumpHeight;
 public LayerMask GroundLayer;


 public Button JumpButton;

 // Use this for initialization
 void Start () {

     Rigid = GetComponent<Rigidbody2D>();
     
 }
 
 // Update is called once per frame
 void Update () {

     Debug.DrawLine(GroundPoint.position,new Vector3(GroundPoint.position.x,GroundPoint.position.y + CheckGroundRadius,GroundPoint.position.z));

     if(OnGround && Input.GetAxis("Jump")>0)
     {
         OnGround = false;
         Rigid.AddForce(new Vector2(0, JumpHeight));
     }



    


 }




 void FixedUpdate()
 {

     OnGround = Physics2D.OverlapCircle(GroundPoint.position, CheckGroundRadius, GroundLayer);

    float Move = Input.GetAxis("Horizontal");
     Rigid.velocity = new Vector2(Move * MaxSpeed, Rigid.velocity.y);


     


 }



 public void MoveLeft()
 {
     Rigid.velocity = new Vector2(-MaxSpeed, Rigid.velocity.y);
 }
 public void MoveRight()
 {
     Rigid.velocity = new Vector2(MaxSpeed, Rigid.velocity.y);
 }
 public void Jump()
 {
     if (OnGround)
     {
         OnGround = false;
         Rigid.AddForce(new Vector2(0, JumpHeight));
     }

 }




}

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 ShadyProductions · Jul 15, 2017 at 10:27 PM 0
Share

Ins$$anonymous$$d of basing it off from the player, base it off the existing platforms. $$anonymous$$now how far your player can jump etc and make an algorithm that can handle this.

0 Replies

· Add your reply
  • Sort: 

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

69 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

Related Questions

Touch and move in any axis 0 Answers

How can I set a timer? 1 Answer

Jump problem help 0 Answers

Moving Walls 1 Answer

Jumping with Character Controller?! 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