C
C
candy3032021-07-15 03:49:03
C++ / C#
candy303, 2021-07-15 03:49:03

How to fix the jump error in this code?

Hello, please help me with this error. Since I have little experience with sishke, I have no idea why this error occurs. Thank you!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Movement : MonoBehaviour
{
    [SerializeField]

    private float moveSpeed = 1f;
  [SerializeField]

    private float jumpForce = 10f;

    [SerializeField]

    private float fallMultiplier = 2.5f;
    [SerializeField]

    private float lowJumpMultiplier = 2f;

    private Rigidbody rb;

    private bool doJump = false;

    private bool isJumping = false;

    void Awake()
    {
    	rb = transform.GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update() {
    	if(Input.GetButtonDown("Jump") && !isJumping) {
            doJump = true;
            isJumping = true;
        }
    }

    // FixetUpdate is called once per fixed Timestep (50 times/second default)

    void FixedUpdate()
    {
        Vector3 moveVect = Vector3.forward;
        moveVect = moveVect.normalized * moveSpeed * Time.deltatime;

        rb.MovePosition(transform.position + moveVect);

        if(doJump) {
            rb.AddForce(Vector3.up * jumpforce, ForceMode.Impulse);
            doJump = false;
        }

        if(rb.velocity.y < 0) {
        	// multiply fall gravity
            rb.velocity += Vector3.up * Physics.gravity.y * (fallMultiplier - 1) * Time.deltatime;
        } else if(rb.velocity.y > 0 && !Input.GetButton("Jump")) {
            rb.velocity += Vector3.up * Physics.gravity.y * (lowJumpMultiplier - 1) * Time.deltatime;
        }
    }
    void OnCollisionEnter(Collision other) {
        if(other.gameObject.CompareTag("Ground"))
             isJumping = false;
    }
}


Error: 'Time' does not contain a definition for 'deltatime'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2021-07-15
@byte916

Capital T
Time.delta Time

M
mrSeller, 2021-07-30
@mrSeller

Howdy, post a link to the bundle to test it live and find a bug

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question