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 AarnasS75 · Jun 26, 2020 at 09:34 AM · 3djumpdistance

How to make object jump a specific distance ? Unity 3D

I'm a complete beginner so this might be simple. How can I make my player to jump to the end point of LineRenderer. So far I managed to make my player jump to the same direction that my LineRenderer points, but I want it to land at the end of the line.

I have this code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Jump : MonoBehaviour
 {
     public Rigidbody rb;
     public float height;
     public Vector3 pos1;   
     public Vector3 pos2;      
     public LineRenderer i0;
     public LineRenderer i1;
     public float power;
 
     void Start()
     {
         pos1 = i1.GetPosition(1);
         pos2 = i0.GetPosition(0);
     }
 
     
     void FixedUpdate()
     {
         
 
         if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began && IsGrounded())
         {
             OnTouchJump(power);
         }
     }
 
     public void OnTouchJump(float power)
     {
         
         Vector3 forceBB = new Vector3(0, 0, 0);
         Vector3 dir = pos2 - pos1;
         Vector3 n = pos1 + (dir / 2);
         n = n + new Vector3(0, height, 0);
         forceBB = n - pos1;
         rb.AddForce(forceBB * power);
     }
    
     private bool IsGrounded()
     {
        return Physics.Raycast(transform.position, Vector3.down, 0.5f);
     }
 }
 
Comment
Add comment · Show 2
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 ShadoX · Jun 26, 2020 at 03:36 PM 0
Share

I'm not super familiar with the LineRenderer, so this might be incorrect, but perhaps you can get the last point on the LineRenderer via

 lineRenderer.GetPosition(lineRenderer.positionCount-1)

and use that to figure out where to go next ? The only issue is that using AddForce to do that might be tricky, so perhaps using something like Transform.Lerp to lerp the objects position from the starting point to the end might work ? though a different issue with that is, that it would probably ignore physics or just end up in issues, if you're moving a Physics object by updating it's Transform.position manually ^_^"

avatar image Boarbox · Jun 26, 2020 at 10:39 PM 0
Share

I highly recommend looking at this talk. It's a bit math heavy but it really helped me out on my game.
https://www.google.com/search?q=game+design+jump&oq=game+design+jump&aqs=chrome..69i57j0.5203j0j7&client=ms-unknown&sourceid=chrome-mobile&ie=UTF-8#

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Eno-Khaon · Jun 27, 2020 at 01:10 AM

By having a LineRenderer point from your character to a target point (i.e. where you touch on the screen), this suggests a rather hands-off approach to making the jump. With that in mind, I would suggest taking a look at a previous post I made regarding trajectory.

Specifically, I could imagine that my examples of HitTargetBySpeed() or HitTargetByAngle() might be the sort of thing you're looking for in this situation.

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

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

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

How to make a ball jump? 2 Answers

Jumping not always work 2 Answers

Double Jump using First Person Controller 1 Answer

In Air Movement 0 Answers

I cant make my character jump 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