#Jump

1 messages · Page 1 of 1 (latest)

heady storm
#

wdym?

primal fable
#

I can send a vid one sec

heady storm
#

changing the raycast distance just modifies how far the player will shoot the raycast downwards to detect the ground

primal fable
#

I don't know, for some reason its not moving up anymore

heady storm
#

what’s the value of your jumpForce?

primal fable
#

10

heady storm
primal fable
#

Yep

heady storm
#

oh actually

primal fable
#

Don't really know how these values impact stuff but I noticed I did have to increase the move speed by a lot before it reached a reasonable speed

heady storm
#

change

playerRigidBody.velocity = Vector3.zero;

to

Vector3 vel = playerRigidBody.velocity;
vel.x = 0;
vel.z = 0;
playerRigidBody.velocity = vel;

You want to preserve the y velocity

heady storm
primal fable
#

My god you are a genius

heady storm
#

was that it? 😅

primal fable
#

Yea

heady storm
#

perfect

primal fable
#

Thanks man ❤️

#

Also quick question

#

Regarding the values that are used, when moving why do I have to make the movement speed variable such a high number?

#

Is this realted to some kind of physic thing? (not really good at physics)

heady storm
#

you’ll have to send more code

primal fable
#
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    // Public Variables
    [SerializeField] public float movementSpeed = 10;
    [SerializeField] public float jumpForce = 10;
    public Rigidbody playerRigidBody;

    //Private Variables
    private InputManager inputManager;
    private Vector3 moveDirection;
    private Transform cameraTransform;

    private void Start()
    {
        inputManager = InputManager.Instance;
        cameraTransform = Camera.main.transform;
    }

    private bool IsPlayerGrounded()
    {
        return Physics.Raycast(playerRigidBody.position, Vector3.down, playerRigidBody.transform.localScale.y / 2 + .1f);
    }

    private void Update()
    {
        Vector2 movement = inputManager.GetPlayerMovement();
        Vector3 move = Time.deltaTime * movementSpeed * (new Vector3(movement.x, 0f, movement.y));
        move = cameraTransform.forward.normalized * move.z + cameraTransform.right.normalized * move.x;
        move.y = 0f;
        moveDirection = move;
    }

    private void FixedUpdate()
    {
        if (moveDirection.magnitude == 0)
        {
            Vector3 vel = playerRigidBody.velocity;
            vel.x = 0;
            vel.z = 0;
            playerRigidBody.velocity = vel;
        }
        else
        {
            playerRigidBody.velocity += moveDirection;
        }
        
        if (IsPlayerGrounded() && inputManager.PlayerJumped() != 0)
            playerRigidBody.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
    }
}
#

This is pretty much the entirety of that script

primal fable
#

400

heady storm
primal fable
#

Oh?

#

I thought you had to do Time.deltaTime

heady storm
#

the code is a bit weird so I’m still thinking about it

heady storm
primal fable
#

I see

primal fable
heady storm
#

remove the Time.deltaTime multiplication but modify the += moveDirection to += moveDirection * Time.fixedDeltaTime. That way it’s technically acceleration instead of increasing the vel every frame

heady storm
primal fable
#

Yea

#

Also, just realized that now the player won't move and only able to jump

#

👀

#

I think its something to do with ```cs
if (moveDirection.magnitude == 0)
{
Vector3 vel = playerRigidBody.velocity;
vel.x = 0;
vel.z = 0;
playerRigidBody.velocity = vel;
}
else
{
playerRigidBody.velocity += moveDirection * Time.deltaTime;
}

primal fable
#
    private void Update()
    {
        Vector2 movement = inputManager.GetPlayerMovement();
        Vector3 move = movementSpeed * (new Vector3(movement.x, 0f, movement.y));
        move = cameraTransform.forward.normalized * move.z + cameraTransform.right.normalized * move.x;
        move.y = 0f;
        moveDirection = move;
    }
heady storm
primal fable
#

Thanks I'll check it out!

heady storm
primal fable
#

I dablled in a few but my primary was TypeScript

heady storm
primal fable
#

It seems like they aren't moving at all but let me actually check the transform prop on the player

heady storm
primal fable
#

Okay so they are moving very very slowly

#

ye velocity is like 0.0005

#

on x and z

heady storm
primal fable
#

Okay so with fixedDeltaTime same thing happens but with the multiplication removed it causes the player to move but very fast

#

Might need to lessen the movement speed from 20 to something lower

heady storm
primal fable
#

nah

#

its 20 now

#

I set it to 20 in the inspector

heady storm
#

hopefully that was it

primal fable
#

Yea I will just lessen the value and hope it still doesn't launch them

heady storm
#

One other thing, is infinite acceleration an issue for you or something you want? If the player continues moving in a straight line, their speed will slowly increase to infinity

#

@primal fable

#

unless I’m mistaken

primal fable
#

Oh yikes

#

ye I don't want them to get faster

#

I want it at a constant speed

heady storm
#

currently it’s doing the second

primal fable
#

The first I would say, in a survival game you want to get out of situations as fast as possible

#

So immediately reaching that speed seems better

heady storm
primal fable
#

Thanks

heady storm
#

Good luck on your game! 🍀

primal fable
#

Thank you 🙂

primal fable
# heady storm Good luck on your game! 🍀

Okay sorry again for bugging you but I realize that I don't quite get how doing math on vectors really works and realize you can only multiply/divide a float on a vector but you can't add or subtract on one. So I am curious as to how people simulate running? Do they make an entirely separate vector for running? So I have the move vector do I need a run vector?

#

Originally I thought I could just do moveDirection + runSpeed and that would increase the speed but then I realized even if that did work it would just add onto the already existing movement speed making them way too fast anyways

heady storm
#

Adding or subtracting by a float wouldn’t make that much sense

heady storm
primal fable
primal fable
heady storm
#

launch?

primal fable
#

Which is due to runSpeed being 15 and the moveDirection essentially just being Vec3(10,0,10)

primal fable
# heady storm launch?

They move very fast in the direction they are looking to the point they get excelled off the platform

heady storm
primal fable
#

yea

#

Which is the problem

heady storm
#

what did you want it to be?

primal fable
#

I want to really increase it to 15 and 15

#

or something slightly faster than walking

heady storm
#

multiply by 1.5f

#

to get 15 and 15

primal fable
#

quick math bro

#

I really suck at math man

#

😔

#

Funny I am going into a profession that requires it but I just suck at it

heady storm
#

I’m probably gonna head to sleep now, if you have another question post it in the main channel and someone can probably solve it, Cheers! ✨

primal fable
#

Sleep well man and thanks for all the help I should probably sleep to

#

2:30am