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
1
Question by Soos621 · Jul 12, 2014 at 02:50 PM · rotationgravity

Rigidbody not being effected by unity's gravity.

Hello, I'm new to unity so forgive my newbish question, anyway i have a character, rigidbody attached with capsule collider, kinematic is turned off and gravity is turned on mass is set to 100 and drag is at 1 but when i move the character over to and edge of terrain (not the end of the terrain object but a "cliff" in the terrain) the character only moves down the y axis at a rate of like .001 per frame. I feel that my rotation script is to blame but i cannot figure out how to fix this problem.

heres my movement script

public class Movement: MonoBehaviour {

 public Transform lookingObj;
 Plane ground;

 void Start () {
 }

 void Update () {

     ground = new Plane(Vector3.up, transform.position);

     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     float dist;

     if (ground.Raycast(ray, out dist)) {
         Vector3 clickPoint = ray.GetPoint(dist);
         Vector3 newClickPoint = new Vector3(clickPoint.x, clickPoint.y, clickPoint.z);
         lookingObj.LookAt(newClickPoint);
     }

 }

}

all the other aspects work fine but if i need to rewrite this code to make the gravity work i will do that.

Thanks a bunch! ~ Soos

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
0

Answer by JusticeAShearing · Jul 12, 2014 at 03:48 PM

I'm not a C# coder, but I have a Java Script that should help you. It requires a character controller, and I've cut out the animations bit for you. It has gravity applied to the character. It also comes with movement, rotation and jumping. I think that character controllers come with Unity. Either that or I got it for nothing off of the Asset Store.

 var speed : float = 6.0;
 var jumpSpeed : float = 8.0;
 var gravity : float = 20.0;
 var rotateSpeed : float = 3.0;
 
 private var moveDirection : Vector3 = Vector3.zero;
 
 function Update() {
     var controller : CharacterController = GetComponent(CharacterController);
     if (controller.isGrounded) {
         //Grounded, so recalculate
         //Move directly from axes
         moveDirection = Vector3(0, 0, Input.GetAxis("Vertical"));
         
         //Rotation Code
         transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0);
         
         moveDirection = transform.TransformDirection(moveDirection);
         moveDirection *= speed;
         
         if (Input.GetButton ("Jump")) {
             moveDirection.y = jumpSpeed;
         }
     }
     
     //Apply Gravity
     moveDirection.y -= gravity * Time.deltaTime;
     
     //Move Controller
     controller.Move(moveDirection * Time.deltaTime);
 }
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 Soos621 · Jul 12, 2014 at 04:26 PM 0
Share

Thank you for your response, unfortunately this script doesn't help me, my movement only goes forward where the rotation of the mouse controls the direction that the character is facing. I attempted to apply the gravity using a vector3 and =- gravity but to no avail. I'm trying to understand why the standard unity gravity on rigidbodies isn't taking effect either.

avatar image JusticeAShearing · Jul 14, 2014 at 04:03 PM 0
Share

I have recently converted from this movement script into one just like that which you have described. I will try to help you further, now that I have the resources. I also have no rigidbody, but may do later.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Rigidbody unaffected by standard unity gravity and script gravity 3 Answers

Rotation of object 0 Answers

Fire Bullet To Mouse Position Problem 2 Answers

Make character walk on walls defying gravity in a 2D Game 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