hi i need to make a jump for my pg in C#... what i command code need to make it? can i see some examples? tnx! :wink:
pg = program? You want to jump to another line of code in C#? You want to make a game object in your scene jump?
The First Person Controller in the standard assets package already implements a basic jump in the attached FPSWalker script. Are you looking to achieve something different?.
no it's ok! but when i try to convert the script in c# unity say it not finished compilation yet!!Why? say this also with Wowcamera script....i don't know whi...
You probably have errors in one or both of the scripts. Here is the FPSWalker in c#: Code (csharp): using UnityEngine; [RequireComponent(typeof(CharacterController))] public class FPSWalker : MonoBehaviour { public float speed = 6.0f; public float jumpSpeed = 8.0f; public float gravity = 20.0f; private Vector3 moveDirection = Vector3.zero; private bool grounded = false; void FixedUpdate() { if (grounded) { // We are grounded, so recalculate movedirection directly from axes moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed; if (Input.GetButton ("Jump")) moveDirection.y = jumpSpeed; } // Apply gravity moveDirection.y -= gravity * Time.deltaTime; // Move the controller CharacterController controller = (CharacterController)GetComponent(typeof(CharacterController)); CollisionFlags flags = controller.Move(moveDirection * Time.deltaTime); grounded = (flags CollisionFlags.CollidedBelow) != 0; } }
Unity is trying to compile all the scripts in your project one or more of your other scripts have errors in them, do you get any errors reported in console window?
oh very very tnx!!!!!!!!!!!!!there are many error in another script!but i don't know because the error in other script (NOT ATTACHED) are the cause of not working game....tnx so much!
Its a good script but there is an error message of "error CS1525: Unexpected symbol 'CollisionFlags' " I dont know whats rong with it but there just is.
i copyed the function (void ) form my movement script i hope is is what you wnated ? void jump(){ Vector3 Motion; Motion = Vector3.zero; CharacterController controller; controller = gameObject.GetComponent<CharacterController>(); //jump if(Input.GetKey(KeyCode.Space)|| controller.isGrounded) { Motion.y = jumpForce; } Motion.y -= gravity * Time.deltaTime; controller.Move(Motion * Time.deltaTime); }
Don't use Input checking in FixedUpdate! This is a confusing and often misunderstood area. As a general rule: Input should be in Update(), so that there is no chance of having a frame in which you miss the player input (which could happen if you placed it in FixedUpdate(), say). Physics calculations should be in FixedUpdate(), so that they are consistent and synchronised with the global physics timestep of the game (by default 50 times per second). Camera movement should be in LateUpdate(), so that it reflects the positions of any objects that may have moved in the current frame. However, there are always exceptions to these, and some experimentation may be required to get what works for you in a given scenario.- tanoshimi
Hi! Here is very simple JUMP: Write before void start: (so you can change value later without touching code) public float upForce = 500f; Then write this in void FixedUpdate: void FixedUpdate() { if (Input.GetKey("space")) // If the player is pressing the "space" key player will move up. { // Add a jump force rb.AddForce(0, upForce * Time.deltaTime, 0); } } Hope it's helpful for some1. Thanks.
[QUOTE = "surmasanteri, post: 3917722, membro: 2336341"] Ciao! Ecco JUMP molto semplice: Scrivi prima dell'inizio vuoto: (quindi puoi modificare il valore in un secondo momento senza toccare il codice) float pubblico upForce = 500f; Quindi scrivi questo nel nulla FixedUpdate: void FixedUpdate () { if (Input.GetKey ("space")) // Se il giocatore sta premendo il tasto "spazio", il giocatore si sposterà verso l'alto. { // Aggiungi una forza di salto rb.AddForce (0, upForce * Time.deltaTime, 0); } } Spero sia utile per some1. Grazie. [/ QUOTE] Potresti mandare direttamente il codice? sono nabbo
so i wrote this code for movement using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMovement : MonoBehaviour { public CharacterController controller; public float speed = 12f; public float gravity = -19.81f; public float jumpHeight = 3f; public Transform groundCheck; public float groundDistance = 0.4f; public LayerMask groundMask; Vector3 velocity; bool isGrounded; private bool onGround; // Update is called once per frame void Update() { isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask); if (isGrounded && velocity.y < 0) { velocity.y = -2f; } float x = Input.GetAxis("Horizontal"); float z = Input.GetAxis("Vertical"); Vector3 move = transform.right * x + transform.forward * z; controller.Move(move * speed * Time.deltaTime); if (Input.GetButtonDown("Jump") && isGrounded) { velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity); } velocity.y += gravity * Time.deltaTime; controller.Move(velocity * Time.deltaTime); } } [/code] the movement on wasd works but the jumping doesnt work i even made all of the objects ground layer but still.
... while at the same time failing to notice you are posting to a thread from 2010. When you have a problem, start your own thread, as per forum rules. It's FREE! Necroposting: How to report your problem productively in the Unity3D forums: http://plbm.com/?p=220 How to understand compiler and other errors and even fix them yourself: https://forum.unity.com/threads/ass...3-syntax-error-expected.1039702/#post-6730855 If you post a code snippet, ALWAYS USE CODE TAGS: How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/ Use code tags: