#how do i do that?
1 messages · Page 1 of 1 (latest)
dunno combine y with y would make more sense
so when did Y come into the picture at all
playerInstance.linearVelocityX = Mathf.Clamp(playerInstance.linearVelocityX + moveX, minX, maxX);
where is clamp Y?
cuz sync said so?
I dont see that anywhere
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?
dont see that being "change it to y"
and regardless we dont focus on Y if up and down, is not needed
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
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
like this?
yes
not important
like a curling thing
whats important is the vlues
this is letting go of keyboard ?
onc eyou press it it doesn t stop
we know the problem already
yeah but it doesn t stop
but do you see why ?
Horizonal should not be above 0
when you let go
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
Do you have a Controller plugged in ?
noop
you're right I misread the debug log lol
only laptop and pc
well it should not be drifting above 0 with no inputs
try changing GetAxis to GetAxisRaw and see what returns
is it stopping now?
noop
okay well at least horizontal now returns 0 which is correct
remove the clamp just for a second, see if its drifting still
did you write
playerInstance.linearVelocityX = moveX
its not moving ?
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
okay then now its certain the clamp was causing issue
maybe clamp the position rather than the velocity
but it expects a 2d vector?
playerInstance.position = Mathf.Clamp(playerInstance.position + moveX, minX, maxX);
dont do + moveX
doesn t seem to matter tried that alr
playerInstance.position = Mathf.Clamp(playerInstance.position, minX, maxX);
so much headache for a stupid game lmao
🙃
wait
where did you even get this code from? a tutorial?
noop trying myself and ai
if you used AI for it, describe the issue to it just like you are to us and you'll get a solution lol
are you trying to clamp position or velocity
and no you shouldn't use " AI"
its just gonna confuse you and teach you nothing
ai is pretty stupid still ahve trust in humans lol
yeahh thing is i just need to do some stuffs in unity for school but isn t really my thing
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
//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
did you test it?
its wrong
yep
works the same as before the edit
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
i mean i can t move fully but it does stop
wdym "cant move fully"
there are invisible barriers
well
thats the whole point of clamp
did you not want to clamp ?
to stop within the road?
oh just set it higher
right
doesn t change im confused
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
oh i see is that a unity thing/
yea
didn t think it mattered in ue5
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
yeah sounds like a more logical thing to do
yus. Hopefully that clears up some confusion
You mean the OnTriggerEnter?
yeah the yellow car has on trigger
should the red one have it?
1 of them needs to be trigger, doesnt matter which one as long is there is 1 dynamic rigidbody between the two
the rigidbody is what calls the Trigger events
i have that but it doesn t work 🤔
did you switch the rigidbody to Dynamic
red kinematic yellow dynamic
which one is the one thats moving
yellow
and the red one has regular collider?
put gravity scale to 0
done doesn t change it tho
surprised you didnt see the car slipping down..
slipping down?
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);
}
}
}
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
but it on dynamic and check the settings?
no no
the code
what did you learn from the player movement
about rigidbodies
and moving code
but why do i need to write code for that too 😭 tought it would work with a component 🤔
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
4 isn t high?
even 1 doesn t work
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);
}
}```
still no collision tho 🤔
unity makes the stupidist game seem like rocket sience
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

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);
}
}
}
Debug.Log("Iets geraakt: " + other.gameObject.name); doesnt appear in console are you sure?
hmm.. show both object inspectors
show me both colliders in scene view
what about it?
select one of the cars so we can see the gizmos
alr what about the player
downscaled
that might be issue
why 😭 unity has so many things you just must know
make the original parents 1,1,1 move the graphics as child object and scale that separately
not saying its for certain but generally you dont want to scale down too much for physics
always scale the graphics as seperate gameobject and keep root around 1,1,1
you did all of them? and spawned them again ?
brought these two to 1
i know but ur changing the prefab that hasnt been spawned
you have to restart with the new prefabs
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
how can i do that?
wdym. just copy the Sprite Renderer component and move it to the child
remove it from parent
can you show a short vid prob the easiest 😅
whats confusing? all ur doing is just moving the graphic to its child
put the order in layer the same exact settings and all that
but is what im doing correct then?
if you removed the Sprite Renderer from the parent yes
ok reset the transform position and put the order in layer back to 2
and why do you have two Car sprites under PlayerCar
you only need 1
but i just want a prefab?
you had to change the prefab
no idea why you made it in the hierarchy
change the Enemy and Player prefabs 🤷♂️
so i can delet those 2?
the child object mate
open the prefab
Open
then do the thing
prefab is its own self-contaned heirarchy
the thing?
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
but how can i make a child object in ue5 i can just right click and do it
have you tried doing the same?
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
but you just created an empty in the scene?
Dont worry bout that part..
its just to show how you create an empty child
you do it in the Prefab hierarchy.. instead..
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
pov your dad trying to teach you math when you are young 🤣
okay thats part 1
now move the graphics to that
COPY the component from PARENT
and paste it in the Child
it says it isn t supported?
i don t see the paste
right click on Transform it will show
right click on the Transform Header / label
now resize the collider on the parent
to match child car size
select both to see both
remove the graphics on the parent obviously
what would be around a normal size dunno how to sleect 2
can u like remove the graphics on the parent if ur gonna send a screenshot
its just confusing everything more
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
just practice and knowing the gui
indeed. you skipped the essentials though so it looks harder than it is
you can delete missing GameObject prefab
now try again and pray the gods?
f zeus
is not working ?
yeahh something else is wrong ig
is this a brand new project?
yeah
like 2D urp template
default 2d
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
it fell because you left gravity on like I said not to do
gravity scale is at 1 therefore its falling..
oh ok my bad still doesn t work
and Sleeping Mode to never sleep
have that
what about CollisionDetection try Continuous
although this slow shouldn't be a problem
noop
void OnTriggerEnter2D(Collider2D collision)
{
Debug.Log($"collided w / {collision.name}");
Time.timeScale = 0;
}
it should be working fine..
and we got the it works on my machine too 😆
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
sure can it be in dm dunno if such file sized can be handled
1.8gb
you don't have this on a github repo? that'd be the best route
thats because ur including the Library folder
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
you got a good gitignore file for that?
if you use Github Desktop it has it in the wizard
got this too if anything
https://www.youtube.com/watch?v=5IxUElilf2M
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...
the gitingore was only supposed to be .gitignore
whut?
oh lol
did you not follow the video? it just makes everything easier with a GUI
done
noop
i don t use gui mostly cmd
like no fancy gui
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
yeah forgot that would normally do that
its fine i think
will delete the repo afterwards anyway nothing special
well want to make sure ur uploading it correct so it works right away lol
i added those 3 by hand
wdym byhand
why just 3 lines
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
it is
alr send link
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
you mean in a good mood?
issa joke but yeah kinda my day off relaxing
i mean i really apreciate your help but i mean i wouldn t pay much money for this shitt of a game XD
not even that, dev consultation / 1 on 1s are pretty expensive nowdays
jesus H
cant believe it was this simpl
ffs
yeah guess so just a student and don t work in tech yett just the airport
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
it doesn t get activated since the spawn doesn t have collision?
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
on enemy doesn t make sense ig
depends on usecase, most time its unusual but valid
yeah but rn theu can collide
when spawning
wdym
spawn in each other
you mean between enemies?
thats what further filtering is for
IE
Checking Tag or the Component directly
then handle accordingly
but can tag on the enemy ig
if you only need
if(other.CompareTag("Player")){ //do stuff with player
enemies dont affect it
unless your enemy was tagged "Player"
right
seems like you know what to do from here
yeah it works
nice
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 🙂
very good
then i need to do a platformer and a groupsgame with 2
(i have to carry to other dude im shitt too XD)
make sure to check the material pinned in #💻┃code-beginner it helped me a lot
best of luck with your projects
can some sources also be checked quick like im not too serious about unity since im used to ue5 and c# is fine but hate microsoft so yeah XD
I mean nothing in development is "quick" lol especially not knowing your way around
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
cuz of assignments for uni
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
any teacher that recommends chatgpt is a fucking tool
and if its uni level thats even more depressing
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)
i mean most ppl become teachers because they can t enter the buisiness side
ofc there are rare examples who really love teaching
some do sure, most are failed at what they did but yeah some do it because they like teaching
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
night!
