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 /
  • Help Room /
avatar image
0
Question by nati12w32q · Mar 15, 2016 at 08:58 PM · rigidbody3daddforcejumping object

addForce problem please help!

alt text

hello , i making a tutorial for fps game , like movement and jumping . im useing addForce to make jump like the tutorial but instead of jumping ith teleporting to the point and falls by gravity. note: im not useing character controller, i create an empty gameobject (like somes tutorials) with camrea as a child. and rigidbody,boxcollider,and my script attach to gameobject. i know this question has asked before ,but i did everything. please see the code ignore the rotation and movment . using UnityEngine; using System.Collections;

public class characterControllerScript : MonoBehaviour {

 public float movmentSpeed = 10f;
 public float mouseSensetivity = 2.5f;
 public float verticalRotationRange = 60f;
 public float jumpForce = 50f;
 private float VerRotation = 0f;
 private double gravity = 0f;
 private float timer = 0f;
 // Use this for initialization
 void Start () {

     Cursor.visible = false;
 }
 
 // Update is called once per frame
 void Update () {
     timer += Time.deltaTime;

     //characterMovment+mouseDirection,depending the mouse facing to so the movment is.
     float horSpeed = Input.GetAxis("Horizontal")*movmentSpeed;
     float verSpeed = Input.GetAxis("Vertical")*movmentSpeed;
     

     float horRotation = Input.GetAxis("Mouse X") * mouseSensetivity;
     transform.Rotate(0, horRotation, 0);

     VerRotation -= Input.GetAxis("Mouse Y") * mouseSensetivity;
     VerRotation = Mathf.Clamp(VerRotation, -verticalRotationRange, verticalRotationRange);
     GetComponentInChildren<Camera>().transform.localRotation=Quaternion.Euler(VerRotation,0,0);
    // Camera.main.transform.localRotation = Quaternion.Euler(VerRotation, 0, 0);
     //  Debug.Log(VerRotation);



     Vector3 speed = new Vector3(horSpeed, 0, verSpeed);
     
     Rigidbody myRG = GetComponent<Rigidbody>();
     speed = transform.rotation * speed;
     myRG.velocity = new Vector3(speed.x,speed.y,speed.z);

     //jumping
     if (Input.GetKeyDown(KeyCode.Space))
     {
      
         GetComponent<Rigidbody>().AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
     }
  

 }

}

pic.png (53.2 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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by RobertoLangarica · Mar 15, 2016 at 09:56 PM

Try without the ForceMode.Impulse or try with another jumpForce value (a really really low one)

Comment
Add comment · Show 1 · 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 RobertoLangarica · Mar 15, 2016 at 09:58 PM 0
Share

Also use FixedUpdate ins$$anonymous$$d of Update when you deal with physics (Explanation here: FixedUpdate)

avatar image
0

Answer by nati12w32q · Mar 16, 2016 at 06:28 AM

i change for FixedUpdate and ith not improving anything. also i delete the Forcemode and tried with low value. ith not working ... please another solution??

Comment
Add comment · Show 3 · 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 RobertoLangarica · Mar 16, 2016 at 06:44 AM 1
Share

FixedUpdate was for other reasons and not to make the jump work. I copy/paste only the jump code and it works by removing the impulse mode. You are forcing the rigid body velocity and that could be your problem. Try with that line commented and see what happen

avatar image nati12w32q · Mar 16, 2016 at 05:28 PM 0
Share

well thanks a lots!! you right about the velocity. i was never paid attention for this. but now there is another problem with the moving character. if i cant use rigidbody.velocity or tranform.position because both make same problem. what can i use to make him move and jump with addForce?

avatar image RobertoLangarica nati12w32q · Mar 16, 2016 at 08:03 PM 0
Share

You could move the character with addForce only in the x Axis, and you could truncate the velocity to a max using rigidbody.setVelocity the problem is that you were overriding the y axis velocity

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

56 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

Related Questions

Time.deltaTime doesn't help on different devices! 0 Answers

Ello~ I need help with transform.parent = null; When I play it and press the DropWeapon input button it goes in a random location and doesnt move . 0 Answers

Jumping cancels out x and z velocity. 0 Answers

So this is the script and I want to be able to boost my speed with a press of a button for example "Jump",Can't increase my movement with GetbuttonDown 0 Answers

How to AddForce to a Rigidbody from Game Objects Spawned from an Array, One Prefab at a Time? 2 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