#how do i do that?

1 messages · Page 1 of 1 (latest)

opal raven
#

hi

modest elk
#

okay lets recap for a second..

#

Why are you passing X values to clamp Y ?

opal raven
#

dunno combine y with y would make more sense

modest elk
#

when did Y come into this

#

do you want it to move up and down?

#

or left to right

opal raven
#

Left and right soX

#

right im confused

modest elk
opal raven
#

playerInstance.linearVelocityX = Mathf.Clamp(playerInstance.linearVelocityX + moveX, minX, maxX);

#

where is clamp Y?

modest elk
#

why did you put linearVelocityY

opal raven
modest elk
#

I dont see that anywhere

opal raven
#

tought this I forgot, you're using 2D physics. might want to change your velocity to just velocity.x or velocity.y. and also, this issue didn't happen when you used update right?

modest elk
#

dont see that being "change it to y"

#

and regardless we dont focus on Y if up and down, is not needed

uncut yacht
# opal raven cuz sync said so?

I said to replace linearVelocity with just velocity.x or y, whichever axis it is. also, since you are in 2D, you might want to change Vector3.zero to Vector2

modest elk
#

how about this....before changing anything..
let us debug the values that are being spit out

#

First thing would be
Debug.Log
so
horizontal = Input.GetAxis("Horizontal");
moveX = horizontal * speed;
Debug.Log($"moveX is {moveX} and horizontal is {horizontal} ");

#

now touch the keyboard (A/D) , and then let go.. Show the console after

opal raven
#

like this?

modest elk
opal raven
#

still sliding like crazy

modest elk
#

not important

opal raven
#

like a curling thing

modest elk
#

whats important is the vlues

modest elk
opal raven
#

onc eyou press it it doesn t stop

modest elk
#

we know the problem already

opal raven
modest elk
#

we're focusing on debugging

#

we know this..

modest elk
#

Horizonal should not be above 0

#

when you let go

uncut yacht
#

I got a solution if nothing works, completely disable the rigidbody component when stationary then reenable it in the code checking for key input :p

modest elk
#

the problem here is clear drifting of the GetAxis

#

letting go should return 0

modest elk
opal raven
uncut yacht
opal raven
#

only laptop and pc

modest elk
#

well it should not be drifting above 0 with no inputs

#

try changing GetAxis to GetAxisRaw and see what returns

opal raven
modest elk
opal raven
modest elk
#

remove the clamp just for a second, see if its drifting still

opal raven
#

yeah just doesn t seem to check it after that

#

doesn t move without the clmap

modest elk
opal raven
modest elk
#

make sure you set it to Dynamic rigidbody

#

oh wait

#

thats why its not moving

#

you put moveX = horizontal underneath it...

#

it has no speed

opal raven
#

oh lol mb

#

yeah without clmaps it works

modest elk
#

okay then now its certain the clamp was causing issue

#

maybe clamp the position rather than the velocity

opal raven
#

but it expects a 2d vector?

#

playerInstance.position = Mathf.Clamp(playerInstance.position + moveX, minX, maxX);

opal raven
#

so much headache for a stupid game lmao

#

🙃

modest elk
#

wait

uncut yacht
#

where did you even get this code from? a tutorial?

opal raven
uncut yacht
#

if you used AI for it, describe the issue to it just like you are to us and you'll get a solution lol

modest elk
#

are you trying to clamp position or velocity

#

and no you shouldn't use " AI"

#

its just gonna confuse you and teach you nothing

opal raven
opal raven
uncut yacht
#

then you might want to check out the pinned messages in the code channels to learn. personally, AI taught me throughout the year but everyone learns differently

modest elk
# opal raven doesn t seem to matter tried that alr playerInstance.position = Math...
//move inputs
var horizontal = Input.GetAxis("Horizontal");
//movement
moveX = horizontal * speed;
//clamping x pos
var clampedPos = Mathf.Clamp(PlayerInstance.position.x, minX, maxX);
//assign velocity from our moveSpeed
PlayerInstance.linearVelocityX = moveX;
//capture current pos
var pos = PlayerInstance.position;
//assign clamped x
pos.x = clampedPos;
//assign clamped position to rigidbody
PlayerInstance.position = pos;```
#

oops

#

edited

opal raven
uncut yacht
#

did you test it?

modest elk
opal raven
modest elk
#

see edit

#

also you can remove the magnitude part

opal raven
#

works the same as before the edit

modest elk
#

it shouldnt because linearVelocityX = horizontal was wrong

#

it should be linearVelocityX = moveX

#

the first one is not accounting for speed

#

so its moving slow limited to a max of 1

#

it should be working just fine now

opal raven
modest elk
opal raven
#

there are invisible barriers

modest elk
#

well

#

thats the whole point of clamp

#

did you not want to clamp ?

#

to stop within the road?

opal raven
#

oh just set it higher

modest elk
#

right

opal raven
#

doesn t change im confused

modest elk
#

what doesnt change?

#

I can test it if you want

opal raven
#

public float minX = -4f, maxX = 5f;

#

setting the values higher

modest elk
#

never change them in the code once serialized

#

aka once its in the inspector, the inspector values take precedence

#

cause Yeah I tested it now and works perfectly

opal raven
modest elk
#

yea

opal raven
#

didn t think it mattered in ue5

modest elk
#

this is only true when the fields are in the inspector

#

if you change it in the code the only way for the inspector to show new values would be to Right click script and hit RESET or reapply script (this obviously gets reset the references to so generally you dont do it this way)

#

but in this case we just change it in the inspector

opal raven
#

yeah sounds like a more logical thing to do

modest elk
#

yus. Hopefully that clears up some confusion

opal raven
#

how does it know the collision on the tag ?

#

are my collision settings still wrong?

modest elk
opal raven
#

should the red one have it?

modest elk
#

the rigidbody is what calls the Trigger events

opal raven
#

i have that but it doesn t work 🤔

modest elk
#

did you switch the rigidbody to Dynamic

opal raven
#

red kinematic yellow dynamic

modest elk
opal raven
#

yellow

modest elk
#

and the red one has regular collider?

opal raven
modest elk
opal raven
#

done doesn t change it tho

modest elk
#

surprised you didnt see the car slipping down..

opal raven
modest elk
#

topdown should not have gravity on

modest elk
#

show EnemyCar code

opal raven
#
using UnityEngine;

public class EnemyCar : MonoBehaviour
{
    public float speed = 5f;  
    void Update()
    {
        transform.position += Vector3.down * (speed * Time.deltaTime);
        if (transform.position.y < -6f)
        {
            Destroy(gameObject);  
        }
    }
}
modest elk
#

ehhh.. you're overriding position thats why it wasnt falling w gravity

#

so from what we went over for the past like hour..

#

what did you learn you should do for EnemyCar if its a Rigidbody

opal raven
#

but it on dynamic and check the settings?

modest elk
#

no no

#

the code

#

what did you learn from the player movement

#

about rigidbodies

#

and moving code

opal raven
#

but why do i need to write code for that too 😭 tought it would work with a component 🤔

modest elk
#

its generally a bad idea to move Rigidbodies in Update and more importantly, of not moving with transform.position but using velocity instead

#

you wont ever get accurate collisions like this, it might work sometimes but its not guaranteed esp if speed is high

modest elk
#

it could be

#

when you do .velocity you are less likely to ever miss that collision

opal raven
#

even 1 doesn t work

modest elk
#

not the point..

#

because in player you're moving the physics first then transform moves too, rather than transform teleporting the rigidbody that might not always catchup on time

#

so again. never move rigidbodies with transform

#

if you want accurate collision

#

    [SerializeField] float speed = 3;
    [SerializeField] Rigidbody2D rb;
    void FixedUpdate()
    {
        rb.linearVelocityY = -speed;
        if (rb.position.y < -6f)
        {
            Destroy(gameObject);
        }
    }```
opal raven
#

still no collision tho 🤔
unity makes the stupidist game seem like rocket sience

modest elk
#

not if you're experienced lol

#

i remade this in 2 mins and its working fine for me

opal raven
#

but how does it not know the collision?

modest elk
#
    void FixedUpdate()
    {
        var horizontal = Input.GetAxis("Horizontal");
        moveX = horizontal * speed;
        var clampedPos = Mathf.Clamp(PlayerPrefab.position.x, minX, maxX);
        PlayerPrefab.linearVelocityX = moveX;
        var pos = PlayerPrefab.position;
        pos.x = clampedPos;
        PlayerPrefab.position = pos;
    }
    void OnTriggerEnter2D(Collider2D collision)
    {
        Debug.Log($"collided w / {collision.name}");
    }```
#
public class EnemyRb : MonoBehaviour
{
    [SerializeField] float speed = 3;
    [SerializeField] Rigidbody2D rb;
    void FixedUpdate()
    {
        rb.linearVelocityY = -speed;
        if (rb.position.y < -6f)
        {
            Destroy(gameObject);
        }
    }
}```
#

working fine here

opal raven
#
    void FixedUpdate()
    {
        if (playerInstance != null)
        {
            //move inputs
            var horizontal = Input.GetAxis("Horizontal");
            //movement
            moveX = horizontal * speed;
            //clamping x pos
            var clampedPos = Mathf.Clamp(playerInstance.position.x, minX, maxX);
            //assign velocity from our moveSpeed
            playerInstance.linearVelocityX = moveX;
            //capture current pos
            var pos = playerInstance.position;
            //assign clamped x
            pos.x = clampedPos;
            //assign clamped position to rigidbody
            playerInstance.position = pos;
        }
        else
        {
            Debug.LogError("PlayerInstance is niet geïnstantieerd! Controleer je prefab toewijzing.");
        }
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        Debug.Log("Iets geraakt: " + other.gameObject.name);

        if (other.CompareTag("Enemy"))
        {
            Debug.Log("Game Over! Speler heeft een vijand geraakt.");
            Time.timeScale = 0;
        }
    }
}
#
using UnityEngine;

public class EnemyCar : MonoBehaviour
{
    /*public float speed = 5f;  
    void Update()
    {
        transform.position += Vector3.down * (speed * Time.deltaTime);
        if (transform.position.y < -6f)
        {
            Destroy(gameObject);  
        }
    }*/
    
    [SerializeField] float speed = 3;
    [SerializeField] Rigidbody2D rb;
    void FixedUpdate()
    {
        rb.linearVelocityY = -speed;
        if (rb.position.y < -6f)
        {
            Destroy(gameObject);
        }
    }
}
modest elk
opal raven
modest elk
opal raven
modest elk
#

in the scene view

#

also dont crop cause its hard to tell whos who..

opal raven
modest elk
#

when you spawn them

opal raven
modest elk
modest elk
opal raven
modest elk
opal raven
modest elk
#

strange

#

that size looks a bit sus tho

#

is your object scaled?

opal raven
modest elk
#

that might be issue

opal raven
modest elk
#

make the original parents 1,1,1 move the graphics as child object and scale that separately

modest elk
#

always scale the graphics as seperate gameobject and keep root around 1,1,1

opal raven
#

so scaled down the prefabs and then?

modest elk
#

you did all of them? and spawned them again ?

opal raven
modest elk
#

i know but ur changing the prefab that hasnt been spawned

#

you have to restart with the new prefabs

opal raven
#

so this is also wrong then?

modest elk
#

well now you have to do the second part I told you

#

move the graphics to a child object and scale that to whatever size you want / match collider on root

#

on the prefab not in game

modest elk
#

wdym. just copy the Sprite Renderer component and move it to the child

#

remove it from parent

opal raven
#

can you show a short vid prob the easiest 😅

modest elk
#

and then resize the collider to match the graphics

opal raven
#

like this im confused

modest elk
#

put the order in layer the same exact settings and all that

opal raven
#

but is what im doing correct then?

modest elk
#

if you removed the Sprite Renderer from the parent yes

opal raven
#

🤷‍♂️

#

picked it from here and puit it beneath playercar and resized it

modest elk
#

and why do you have two Car sprites under PlayerCar

#

you only need 1

opal raven
modest elk
#

you had to change the prefab

#

no idea why you made it in the hierarchy

#

change the Enemy and Player prefabs 🤷‍♂️

opal raven
modest elk
#

just modify them

#

no need to make a brand new object..

opal raven
#

but these are now fullsize and they can t be 0.2 how can i fix that then?

modest elk
#

the child object mate

#

open the prefab

#

Open

#

then do the thing

#

prefab is its own self-contaned heirarchy

opal raven
#

the thing?

modest elk
#

passing the graphics to the child object?

#

so you can resize without touching the entire car?

#

thats the whole point of seperating the Graphics/Visuals from the Root object

#

so you can resize the looks without touching the parent

opal raven
#

but how can i make a child object in ue5 i can just right click and do it

modest elk
#

have you tried doing the same?

opal raven
modest elk
#

nah

#

not there

#

you gotta open the prefab to work with the heirarchy

#

thats where you do it

#

its really not that difficult if you actually learned the tool you're using

#

you're just kinda guessing around ofc everything is going to be seem difficult

opal raven
modest elk
#

Dont worry bout that part..

#

its just to show how you create an empty child

#

you do it in the Prefab hierarchy.. instead..

opal raven
#

you want it like this?

modest elk
#

jesus h

#

no

#

not at all

#

not even close

#

why did you do this

#

this is taking 2 hours when it should take 10 mins lol

opal raven
modest elk
#

you did not press OPEN like I said before.

opal raven
modest elk
#

okay thats part 1

#

now move the graphics to that

#

COPY the component from PARENT

#

and paste it in the Child

opal raven
#

it says it isn t supported?

modest elk
#

anyways about to head out, better do this quick

opal raven
#

i don t see the paste

modest elk
opal raven
modest elk
#

right click on the Transform Header / label

opal raven
modest elk
#

okkkk

#

reset the position and now resize it

opal raven
modest elk
#

why did move everything to child..

#

just the visuals man

#

comon

#

pay attention

opal raven
modest elk
#

to match child car size

#

select both to see both

#

remove the graphics on the parent obviously

opal raven
modest elk
#

can u like remove the graphics on the parent if ur gonna send a screenshot

#

its just confusing everything more

opal raven
modest elk
#

select Player Car in the heriarchy not the project view.

#

ur working within the scope of the prefab now.

#

you only look at the hierarchy

opal raven
modest elk
#

there ya go

#

now do u see what you need to do with the size of collider ?

opal raven
modest elk
#

okay now do the same for the other car

#

not that diffcult is it

opal raven
modest elk
#

indeed. you skipped the essentials though so it looks harder than it is

opal raven
modest elk
#

ok now press Back arrow on prefab to save

opal raven
modest elk
#

you can delete missing GameObject prefab

opal raven
#

now try again and pray the gods?

modest elk
#

pretty much

#

if it still not working, something else unexpected is going on

opal raven
#

f zeus

modest elk
#

is not working ?

opal raven
#

yeahh something else is wrong ig

modest elk
#

is this a brand new project?

opal raven
#

yeah

modest elk
#

like 2D urp template

opal raven
modest elk
#

long shot but try putting the rigidbody2d on the player to Dynamic(set gravity scale to 0) instead of kinematic or also "Sleeping Mode" to Never sleep

opal raven
#

my car falls down too then

#

on dynamic i think

modest elk
#

it fell because you left gravity on like I said not to do

opal raven
modest elk
#

gravity scale is at 1 therefore its falling..

opal raven
#

oh ok my bad still doesn t work

modest elk
#

and Sleeping Mode to never sleep

opal raven
modest elk
#

what about CollisionDetection try Continuous

#

although this slow shouldn't be a problem

opal raven
#

noop

#

void OnTriggerEnter2D(Collider2D collision)
{
Debug.Log($"collided w / {collision.name}");
Time.timeScale = 0;
}

modest elk
#

it should be working fine..

opal raven
#

and we got the it works on my machine too 😆

modest elk
#

well could be something broken in the project somehow.. not sure..

#

if you want you can try uploading the project and I can test it

opal raven
#

1.8gb

modest elk
modest elk
#

the only important folders are
Assets
Packages
Project Settings

#

the best way to do it seamless + it will give you benefit of backups / reverting would be just using version control

opal raven
#

you got a good gitignore file for that?

modest elk
#

if you use Github Desktop it has it in the wizard

#

Link to Github Desktop GUI Client: macOS / Windows
https://desktop.github.com/

For my Ubuntu/Mint Linux Friends, Install Github Desktop by using following commands:
sudo wget https://github.com/shiftkey/desktop/releases/download/release-3.1.1-linux1/GitHubDesktop-linux-3.1.1-linux1.deb
sudo gdebi GitHubDesktop-linux-3.1.1-linux1.deb

Info on L...

▶ Play video
opal raven
#

shows this with the git ignore is that fine don t wanna bloat github lol

modest elk
#

the gitingore was only supposed to be .gitignore

modest elk
opal raven
#

oh lol

modest elk
opal raven
#

done

opal raven
#

i don t use gui mostly cmd

#

like no fancy gui

modest elk
#

ok well regardless the file in the root of project should be initial committed with a .gitignore exactly with that

#

make a new repo if you have to

#

make sure its correct

opal raven
#

yeah forgot that would normally do that

opal raven
#

will delete the repo afterwards anyway nothing special

modest elk
#

well want to make sure ur uploading it correct so it works right away lol

opal raven
#

got the 3 folders?

modest elk
#

yeah but why is it Unity.gitignore

#

did it only track those 3 folders

#

make sure

opal raven
opal raven
modest elk
#

wdym byhand

opal raven
#

git add Assets/

#

etc

modest elk
#

oof

#

alr whatever

opal raven
modest elk
#

i mean the ideal thing would be tracking the project root with proper ignore so you only add the main but whatever

#

just make it public so it can be dl real quick and then put it back to private

modest elk
#

alr send link

opal raven
modest elk
#

ok im on 33 so it needs to rebuild while upgrading

#

should be open in 5 min

#

lucky I'm donation day today , normally this cost money lol

opal raven
modest elk
#

issa joke but yeah kinda my day off relaxing

opal raven
#

i mean i really apreciate your help but i mean i wouldn t pay much money for this shitt of a game XD

modest elk
#

not even that, dev consultation / 1 on 1s are pretty expensive nowdays

#

jesus H

#

cant believe it was this simpl

#

ffs

opal raven
modest elk
#

just realized your CODE that controls the car is the SPAWNER not the CAR itself

#

OnTrigger checks the Object ITS ON

#

well that was a good wasted hour lol

#

for some reason I mistaken the move script as separate script from your spawner

#

okay well easy fix then

#

lol if only OnTriggerEnter was on the Enemy script car it would've worked right away...

#

you understand the problem now ? @opal raven

opal raven
modest elk
#

correct

#

OnTrigger needs to be on the gameobject with the COLLIDER between the TWO objects that are involved

#

doesnt matter which one, as long as its one between the two

#

So either Put the OnTrigger logic on the Enemy , or make the PlayerMovement of the car a separate script and put that on the player prefab instead, then only keep the Spawning in the spawner

opal raven
#

on enemy doesn t make sense ig

modest elk
#

depends on usecase, most time its unusual but valid

opal raven
#

when spawning

modest elk
#

wdym

opal raven
#

spawn in each other

modest elk
#

you mean between enemies?

#

thats what further filtering is for
IE
Checking Tag or the Component directly

#

then handle accordingly

opal raven
#

like this

modest elk
opal raven
#

but can tag on the enemy ig

modest elk
#

if you only need

if(other.CompareTag("Player")){ //do stuff with player

#

enemies dont affect it

#

unless your enemy was tagged "Player"

opal raven
modest elk
#

right

opal raven
modest elk
#

seems like you know what to do from here

opal raven
modest elk
#

nice

opal raven
#

thank you so much for your help gonna get some sleep (it is over midnight) and try to implement some more vehicles tomorrow and start and endscreen and call it done 🙂

modest elk
#

very good

opal raven
#

then i need to do a platformer and a groupsgame with 2

#

(i have to carry to other dude im shitt too XD)

modest elk
#

best of luck with your projects

opal raven
modest elk
#

it probably wont be overnight.. If you dont plan on staying in unity why even learn it at all ?

#

I personally find Unreal ineteresting looking but its a pain to work with compared to unity

opal raven
#

was either free pass for 5 points

#

was data but even the teacher said you could do it in 1 hour with chatgpt

#

or serious gaming making 3 games and a groupsgame

modest elk
#

any teacher that recommends chatgpt is a fucking tool

#

and if its uni level thats even more depressing

opal raven
#

and was a side project so didn t give it too much time made 1 and my group was ass (like in general not taling about unity)

opal raven
#

ofc there are rare examples who really love teaching

modest elk
#

some do sure, most are failed at what they did but yeah some do it because they like teaching

opal raven
#

got 2 of those the rest is there mainly for the money

#

anyway was nice meeting you but gonna sleep cuz almost faslling asleep behind my desk

modest elk
#

night!