#Jump
1 messages · Page 1 of 1 (latest)
changing the raycast distance just modifies how far the player will shoot the raycast downwards to detect the ground
I don't know, for some reason its not moving up anymore
what’s the value of your jumpForce?
10
and this is according to the inspector right?
oh actually
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
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
See if it works when you are going forwards
My god you are a genius
was that it? 😅
Yea
perfect
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)
you’ll have to send more code
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
how high is the number?
400
When you create move you don’t need the Time.deltaTime multiplication
the code is a bit weird so I’m still thinking about it
essentially Time.deltaTime is 1/fps. So if you are running 60 frames per second, it’s 1/60. If you are running 150 frames per second, it’s now 1/150 which is an even smaller number
I see
If you have any tips on how to make my code better I am all ears, I am not the best C# programmer
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
are you a programmer in a different language?
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;
}
show move direction
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;
}
I recommend this playlist a lot to people who’ve programmed before. It’s pretty fast paced and they explain the unity workflow well. Up to you which video you decide to start, but all of them have good info. Unity stuff specifically starts at the second half of episode 2. https://youtu.be/9iCnjdXEfMA?list=PLFt_AvWsXl0fnA91TcmkRyhhixX9CO3Lw
Thanks I'll check it out!
which language if you don’t mind me asking 😄
I dablled in a few but my primary was TypeScript
Is the player completely not moving or moving very slowly?
It seems like they aren't moving at all but let me actually check the transform prop on the player
you can check by looking under the info tab on the rb
maybe change it to Time.fixedDeltaTime. If that doesn’t work, try removing the multiplication
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
you still have the speed at 400 or so? that’s why
hopefully that was it
Yea I will just lessen the value and hope it still doesn't launch them
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
one other thing, did you want them to reach that constant speed immediately or accelerate to that speed?
currently it’s doing the second
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
oh then even easier. Replace the += with an = and re-adjust the speed accordingly
Thanks
Good luck on your game! 🍀
Thank you 🙂
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
you can do Vector3 +Vector3 or Vector3 * float
The first performs the operation (a.x + b.x, a.y + b.y, a.z + b.z)
The second performs the operation (a.x * f, a.y * f, a.z * f)
Adding or subtracting by a float wouldn’t make that much sense
usually for running, they just multiply it by runFactor or something
I see makes sense
What would run factor be? Cause right now I am doing moveDirection * runSpeed and that makes them launch rathe then actually run
launch?
Which is due to runSpeed being 15 and the moveDirection essentially just being Vec3(10,0,10)
They move very fast in the direction they are looking to the point they get excelled off the platform
ah then the velocity becomes 150 and 150
what did you want it to be?
I want to really increase it to 15 and 15
or something slightly faster than walking
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
don’t worry, the computer is too https://0.30000000000000004.com/
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! ✨