#Never tried making one probably usefull

1 messages · Page 1 of 1 (latest)

glass siren
frail bay
#

oh,should i use this instead?

glass siren
#

this

frail bay
#

okii,sorry for the mistake

glass siren
#

no worrys I never tried making one of these

frail bay
#
    Rigidbody rb;

    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        float xloc = Input.GetAxis("Horizontal");
        float zloc = Input.GetAxis("Vertical");
        float yloc = Input.GetAxis("Vehicleup");
        rb.velocity = new Vector3(xloc * speed, yloc * speed, zloc * speed);
    }```
#

they seem pretty usefull,especially in this situation

#

vehicleup is basically shift and controll for up/down

glass siren
#

Oke so the problem was that he was going the wrong direction?

frail bay
#

yea,if he were to rotate to face another direction

#

if he were to face towards the camera and i was to press on W then he'd move backwards

glass siren
#

O

#

you want to have forward always be forward even if the player rotates

frail bay
#

yea!

glass siren
#
    public float speed = 10f;
    Rigidbody rb;

    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        Vector3 targetVelocity = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), Input.GetAxis("Vehicleup") * speed);      
        rb.velocity = transform.TransformDirection(targetVelocity);
    }
#

try this

#

transform.TransformDirection

#

rotates the direction vector based on the player transform

frail bay
#

ooooh,that seems very usefull!

glass siren
#

I think I do this in about every project

frail bay
#

it works!!

#

i never thought of just putting the horizontal vertical and vehicleup in a vector3,thats actually pretty smart

glass siren
#

Ye that keeps the code way cleaner, you also might want to use the new input system

frail bay
#

i gotta get used to thinking like that.,.

#

new input system?

glass siren
#

Ye you can find it in the package manager, there is plenty tutorials about it

frail bay
#

oh,could you send me a tutorial on it please?

glass siren
#

✅ Get the FULL course here at 80% OFF!! 🌍 https://unitycodemonkey.com/courseultimateoverview.php
👍 Learn how to make BETTER games FASTER by using all the Unity Tools and Features at your disposal!
👇
🌍 Get my Complete Courses! ✅ https://unitycodemonkey.com/courses
👍 Learn to make awesome games step-by-step from start to finish.
🎮 Get my Steam Gam...

▶ Play video
#

very long video but when you know how to use it it's pretty easy

frail bay
#

thank youu!!

#

and i hope you'll have a awesome day!

glass siren
#

A no problem man, you can always ask my anything about Unity, I'm currently working a lot with Unreal and I get bored from that sometimes so I like helping people with Unity