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 Bogdan003 · Oct 26, 2019 at 07:44 PM · movementscript.jumping

I can't write a realistic jumping script,help!

So i am trying to do a portal-like game but for which i need realistic jumping,and obviously i cant do it...I am using a rigidbody and a capsulecollider not a charactercontroller , i'd be really greatful if you'd help.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 public class PlayerController : MonoBehaviour
 {
     public Animator anim;
     [SerializeField] float moveSpeed = 4f;
     [SerializeField] float rotationSpeed = 4f;
     Vector3 forward, right;
     Rigidbody rb;
     void Start()
     {
         anim = GetComponent<Animator>();
         forward = Camera.main.transform.forward;
         forward.y = 0;
         forward = Vector3.Normalize(forward);
         right = Quaternion.Euler(new Vector3(0, 90, 0)) * forward;
     }
     void Update()
     {
         if (Input.anyKey)
             Move();
         if (Input.GetKeyDown("w") || Input.GetKeyDown("a") || Input.GetKeyDown("s") || Input.GetKeyDown("d"))
         {
             anim.SetBool("iswalking", true);
         }
         else { 
             anim.SetBool("iswalking", false);
         }
     }
     public void Move()
     {
 
         Vector3 direction = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
 
  
         Vector3 rightMovement = right * moveSpeed * Time.deltaTime * direction.x;
      
 
       
         Vector3 upMovement = forward * moveSpeed * Time.deltaTime * direction.z;
     
 
 
         Vector3 heading = Vector3.Normalize(rightMovement + upMovement);
 
         transform.forward = Vector3.Lerp(transform.forward, heading, Time.deltaTime * rotationSpeed);
 
         transform.position += rightMovement;
         transform.position += upMovement;
 
     }
 }
 
     
   
 
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

4 Replies

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

Answer by Bogdan003 · Oct 27, 2019 at 10:47 AM

GUYS FGET BOUT IT ! IT WAS THE Y AXIS DIRECTION THAT WAS WRONG

NYWAY THANK U ALL ##

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
avatar image
1

Answer by Xrsftw · Oct 26, 2019 at 08:49 PM

I think you shouldn’t use transform.position += ... And instead use rb.AddForce or rb.MovePosition to move your player. Then the physic engine of unity will have a better understanding of what are you trying to do. Also remember to transfer your code in FixedUpade instead of Update if you want a physics based movement.

Comment
Add comment · Show 2 · 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 Bogdan003 · Oct 26, 2019 at 09:16 PM 0
Share

tbh i don't really know how i could implement that...

avatar image Bogdan003 · Oct 27, 2019 at 10:20 AM 0
Share

Ok so i tried making the gravitational force stronger and i got some good results when falling but when i try to jump by using if (Input.Get$$anonymous$$eyDown("c")) { rb.AddForce(Vector3.up *jumpforce); } it rotates the character in every posible direction , i tried locking the rotation but this way he doesnt even move...

avatar image
0

Answer by TheShadyColombian · Oct 26, 2019 at 08:30 PM

Heya so this question is kinda vague but I'll still try to give some advice:

First of all, what do you mean by "realistic"? Assuming your physics are working fine, your player should already have the most realistic movement it'll ever have. You apply upwards force, the physics engine will take care of reducing that velocity, colliding on the ground, etc.

I have a feeling you mean the jumping doesn't feel good, which would make more sense, and is a whole other can of worms. If that is the case, that 's something that can be solved by improving your game feel. Camera sway, shaking, subtle little things like that can give you that extra feeling of "weight". Giving your camera some movement based on the player velocity is typically one way in which a player's jump is made to feel better.

But all of this is, in my opinion, pretty irrelevant for you right now. If you're planning on developing this game completely, these improvements to the game feel should be left until the end. It's all just polish. Your main priority should be in completing a full prototype, then you can consider moving onto a vertical slice of your game if you're happy with the way the game plays.

Lastly, and I'm sure most people will tell you this, I'm worried you might have too broad a scope for a one person project. If this is a small project for you to just mess around and gain experience, then that's good, but I'm afraid I don't see this project being something that one person can finish on their own.

Best of luck on your project though! If you need some clarification on anything I mentioned feel free to leave a comment, or send me a DM (not sure if Unity Answers has those though :\ )

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
avatar image
0

Answer by Reedex · Oct 26, 2019 at 09:54 PM

This ytb link has interesting observations along with simple code. : - ) although it's presented in 2d. https://www.youtube.com/watch?v=7KiK0Aqtmzc

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

188 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 avatar image avatar image avatar image 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

jumping from ledge problem 1 Answer

2D "Platformer" Movement Problems 1 Answer

Is this sprint/stamina script optimal or wasting performace? 0 Answers

How to use Android Accelerometer(Left and right tilt) to turn a sphere object and camera in that direction? 1 Answer

Character not jumping when moving 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