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
-1
Question by afortiori05 · Oct 30, 2018 at 02:26 PM · jumpingfps controllerspacebar

so could somebody make me a simple jump script in c# for an fps character without using rigidbody? i dont know why but rigidbody isnt working on my character. i also want to be able to jump using spacebar.

@Mike 3 @Bunny83 @Eric5h5 @aldonaletto @tanoshimi @whydoidoit @duck @fafase @clunk47

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
Best Answer

Answer by Tanoshimi2000 · Oct 30, 2018 at 02:54 PM

For a simple jump (before I had access to rigid bodies) I liked to use the Sine function. As in:

Y=Sin(cnt) cnt+=1

It could be more involved than that, with checking for ground collisions in case they're jumping up on a box or platform. But the basic premise is that Y is incremented in each iteration of the Update function with the Sine of cnt or Timer, which runs from 0 to 1 and back to 0 when cnt is run from 0 to 180.

Of course, you could also just do: jumpamount=1 y+=jumpamount if Y>jumpheight then jumpamount=-1 if Y

Basically, there are easy ways to do it without RigidBodies.... but I don't recommend it. You're better off figuring out why the RB isn't working.

Comment
Add comment · Show 6 · 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 afortiori05 · Oct 30, 2018 at 04:13 PM 0
Share

TY bro i will take your advice do you have any idea why the RB wouldnt be working?

avatar image Tanoshimi2000 afortiori05 · Oct 30, 2018 at 04:46 PM 0
Share

I have a thought or two. It's less important to know WHY it's NOT working, than it is to just get it to work. So...

First, make sure you have a collider. RigidBodies practically require them.
Second, try starting with a simple object, like a box, add a rigid body and see if you can get that to work. If so, then start adding things slowly, like replace the box with your model, then add in the animations, then other scripts. Next, why not just use the prefabs that come with Unity? Take the Third Person Controller prefab, drop it in your project and hit play. It should just work. Then you can change their model to yours, etc. Also, which functions are you using in Rigid Bodies? Like, if you try changing the transform, that will overrule the RB physics. For example, if you use RB.AddForce(Vector3.Up * 10) to get him to jump, but in another section or script have something that affects the transform, like transform.Y = transform.Y-Gravity, that's going to negate any forces. Physics is the world acting on things, Transform is God acting on things. Or the programmer/creator. It's the higher power (literally).

Hope this helps. If not, you can hit me up outside this stream via e-mail and we can figure it out.

avatar image afortiori05 Tanoshimi2000 · Oct 30, 2018 at 06:19 PM 0
Share

so i am using a character controller for my player and it seems that rigidbody isnt compatable with the character controller it just keeps spinning and flying all over. is this supposed to be happening? and the character controller is neccesary for the script i have so if i could mabie just show you the script and you could show me where to put the simple jump scripts you have in the answer...this is the script can you fix it? using System.Collections; using System.Collections.Generic; using UnityEngine;

public class fpsController : $$anonymous$$onoBehaviour { public float speed = 2.0f; public float sensitivity = 2f; CharacterController player;

  public GameObject eyes;
 
  float moveFB;
  float moveLB;
 
  float rotX;
  float rotY;
 
  
 
  private void Awake()
  {
      LockCursor();
  }
 
 
 
  private void LockCursor()
  {
      Cursor.lockState = CursorLock$$anonymous$$ode.Locked;
  }
 
 
 
  // Use this for initialization
  void Start()
  {
      player = GetComponent<CharacterController>();
 
  }
 
  // Update is called once per frame
  void Update()
  {
      moveFB = Input.GetAxis("Vertical") * speed;
      moveLB = Input.GetAxis("Horizontal") * speed;
 
      rotX = Input.GetAxis("$$anonymous$$ouse X") * sensitivity;
      rotY = Input.GetAxis("$$anonymous$$ouse Y") * sensitivity;
 
      Vector3 movement = new Vector3(moveLB, 0, moveFB);
      transform.Rotate(0, rotX, 0);
 
      eyes.transform.Rotate(-rotY, 0, 0);
 
      movement = transform.rotation * movement;
      player.$$anonymous$$ove(movement * Time.deltaTime);
 
 
 
 
 
 
  }
 
 
 
 

}

Show more comments

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

158 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

Related Questions

How to prevent jumping off held object? 0 Answers

Character sometimes moves faster when I jump and start moving at the same time 1 Answer

Physics.Raycast not working 1 Answer

FPS Jump Help 0 Answers

Standard FPS Controller - Sounds Cancelling One Another 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