#Pogo Help 1032021

1 messages · Page 1 of 1 (latest)

lucid galleon
#

What's your code, @torn basin ?

torn basin
#

give me a second

lucid galleon
#

Remember to post it here by using three `'s

torn basin
#
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    //variable you can change in Inspector
    public float sidewaysForce = 400f;
    //makes player's rigidbody "rb"
    public Rigidbody rb;

    void Update()
    {
        //right movement
        if (Input.GetKey("d"))
        {
            rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
        }

        //left movement
        if (Input.GetKey("a"))
        {
            rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
        }

    }
}
#

it adds a force to the rigidbody if u press a or d (i made a variable for that that I can change in inspector)

#

and then did all the Time.delta stuff that I don't really understand

lucid galleon
#

Sorry for waiting

torn basin
#

np

lucid galleon
#

Hmm...

torn basin
#

i think a slippery floor would fix it, but more problems would come up later

#

not sure how to do player movement any differently though

lucid galleon
#

No, hmm

#

You should use a characterController

torn basin
#

I am very new to code

#

What's a CharacterController?

torn basin
#

I'm trying not to just ctrl+c and ctrl+v

broken trail
#

It's fine to use physics, but there are a few things you need to remember:
add forces in FixedUpdate, as that is when unity simulates physics.

#

Input shout still be in regular update.

torn basin
#

ah so change Update to FixedUpdate?

#

wait what

#

I am confused

#

Sorry

broken trail
#

And you don't need to multiply force by delta time. You could(considering it's in fixed update, deltaTime = fixedDeltaTime), but don't have to.

lucid galleon
#

Oh wait, you want physics

broken trail
torn basin
#

give me a sec

lucid galleon
#

IN the rigidbody settings, click freezeRotation.x

broken trail
#

What was the problem anyways?

lucid galleon
#

Also z, then re-enable it if you wanna do like Ragdolls

torn basin
#

can you have functions in functions?

lucid galleon
#

No, you can't

broken trail
#

it's called local functions.

lucid galleon
#

Ohhh I see

#

Wow, I learned something new

torn basin
#

i am very confused how i add the forces in FixedUpdate but inputs in normal Update

broken trail
#

Yeah. I use them like once or twice in a year.😅

broken trail
torn basin
#

I am so confused

#

I am sorry

#
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    //variable you can change in Inspector
    public float sidewaysForce = 0f;
    //makes player's rigidbody "rb"
    public Rigidbody rb;

    void Update()
    {
        //if d is pressed, ---
        if (Input.GetKey("d"))
        {
            moveRight();
        }

        //if a is pressed, ---
        if (Input.GetKey("a"))
        {
            moveLeft();
        }

    }

    void FixedUpdate()
    {
       
    }
}
#

i got this far

#

I think thats what you mean?

#

I dont really know the technical terms

broken trail
#

I'm not sure what moveRight and moveLeft are. And you don't have anything in fixed update. You could just move the AddForce calls to FixedUpdate as they are.

torn basin
#

I thought like

#

idk

#

but how do I link the "if _ is pressed" in the update to the AddForces

broken trail
#

There are a few ways, but think logically. What type do you check in an if statement?

torn basin
#

I cant think logically

broken trail
#

Let's say Input.GetKey("d"). What does it return?

torn basin
#

true or false?

#

I think

broken trail
torn basin
#

bools?

broken trail
#

yes

#

So you can store these values in a bool

#

and use them in FixedUpdate

torn basin
#

OH

#

i think i get it

broken trail
#

That's what we refer to when we say "cache something" usually.

coarse stag