#💻┃code-beginner
1 messages · Page 555 of 1
it moves a little every frame until it reaches the amount of jump after 1 second . . .
you want it to reach the amount of jump during that one frame, hence, using Impulse ForceMode . . .
force is time dependant (F = ma = mv/t), impulse, aka momentum, is not (P = mv)
playerRB.AddForce(Vector3.up, ForceMode mode = ForceMode.Impulse * jump);
it says i cant multiply it now
so how do i add the jump
This syntax doesn't make sense. Take a moment to analyze what you're trying to do here.
You can make your own enum flag.
[Flags]
public enum F {
FlagOne = 1 << 0
FlagTwo = 1 << 1
FlagOneAndTwo = FlagOne | FlagTwo
}
1 << n basically means shift this bit to the left.
0b000000000000000000000000000001 also works to explicitly lay out the bits but that's wonky.
Enums inherit int by default, which has 32 bits.
this is all types of wrong lol
when passing a value you don't use = in the signature
oh my god🤣
see no idea how to read the documentation
i thought you are creating a local variable just for that
thats just c# basics nothing to do with docs
huh, well i dont understand a single thing, ill have to take a tutorial for me to understand better and actually apply this
or an object of ForceMode
thanks either way!
no you didnt... do you see the comma in between
i did put a comma
you copied a declaration
you need to write a call
separate things
its important you learn these c# basics
i know how to pass arguments haha it's the same in cpp
the declaration tells you how to call it, it doesn't show how to call it
When the docs say that, it just means that's the default value of that.
then why did you add a parameter declaration and an assignment
then why are you using the declaration of a method instead of just passing value
i thought it's different here idkðŸ˜
The parameter arguments when used are in the same order as usual.
it isn't
so where do you see that
Unity is just showing you how the method was declared in their codebase
here
i meant to reply to this
ah
are we going in circles here
do you drive a car without looking once in the manual... thats how you use unity without using the docs...
but the doc is not telling you how to write the thing
yes it is... just scrolling down
public void AddForce(Vector3 force, ForceMode mode = ForceMode.Force)
there's a parameter list that specifies Vector3 force and ForceMode mode, and mode has a default (=) of ForceMode.Force
when you want to set a mode yourself, ignore the default
so you pass a Vector3 and a ForceMode
the doc expect you some basic knowledge of how to use the c# code properly
yes, because c# does
You can use paramName = ... to specify which argument you meant.
AddForce(Vector.Up * jump, ForceMode = ForceMode.Impulse);
This is valid code.
This feature exists when you want to leave the other default arguments as is.
you even have an example in the docs..
i know how docs work, yes.
But otherwise, you can omit and pass the arguments in order.
this doesn't work
ForceMode is the type, not the parameter name
oh sry was the wrong... msg sould be for barkov..
(also up is in camelCase)
the example in the doc showed me Input.GetButton and then i clicked it and it said not to use that
I forgot this is Unity.
and then i got lost haha
Oh it's mode.
that is irrelevant lmao
I thought the param is ForceMode.
huh where does it say not to use it
Note: This API is part of the legacy Input class, and not recommended for new projects. The documentation is provided here to support legacy projects that use the old Input Manager and Input class. For new projects you should use the newer and Input System Package. (read more).
You can use paramName = ... to specify which argument you meant.
AddForce(Vector.up * jump, mode = ForceMode.Impulse);
This is valid code.
This feature exists when you want to leave the other default arguments as is.
Ok fixed.
yeah that's correct but you can ignore it for now
you have bigger fish to fry
ohh sure, Input class is being phased out no big deal
It doesn't because it's obvious for anyone that knows C# basics(or even C++ basics).
you can still use it
idk i just saw not recommended and was like alright then
c#, c++, and many others are part of the c family, they share a lot of basic syntax features
including method calls and declarations
iss tru
but it's more than that it's the names
it isn't
Impulse for exapmple is not part of the c# language
theres even a 2nd example with what you would have needed..
that doesn't matter
it's just a value you pass of some given type
The syntax doesn't change
all it changes are the types declared
the basic syntax for method declarations and method calls is identical in c, c++, c#, java, and probably some others
OH!
there's some differences with modifiers, generics/templates, defaults, and named params, but the core of it really is just the same
WAIT
doesnt change anything how C# works
i think i got it
specific unity things are anything inheriting UnityEngine usually like Monobehaviour
ForceMode mode = ForceMode.Force
basically means that the second part of that code after the comma you need to write the mode you want from ForceMode but with a dot
I've tried C. Define is amazing imo.
no, that's not what that means
To a degree that I think it would be cool if C# have it.
ffs
it requires a ForceMode type, which is an enum, so you have to get a member of that enum
you could also cast some other value to ForceMode
ohh and that's where preknowledge comes from
cuz you gotta know that you do that with a dot
okay i see
iirc (ForceMode)0 would also be a valid ForceMode value, it'd be equivalent to ForceMode.Force
because it's ordered?
you just need some value of the given type
you write that forcemode with a dot.. cause its an enum you call.. Forcemode. variable
like an array?
I think just 0 is valid.
yeah enums are inherently ordered
unless you specify the values, they start from 0 ye
yes now the thing clicked in my brain
if it would be another parameter you would call that ...
(you don't call it)
Enums are an int.
Where some of its value is named.
(enums are an integral type, not necessarily int)
you see what this thing is a class enum etc and then treat it accordingly with knowledge you have about the language
yeah correct sry, my english/german sometime meses up^^
the ForceMode mode = ForceMode.Force in declaration is a default parameter. Meaning that if you don't pass in anything at that position, it would be the default value.
This is the same in C++ iirc.
you can't use anything unity provides without knowing how to use the thing it's building on
you can't use the unity editor without knowing how to use a GUI
you can't use unity apis without knowing how to use c#
i figured it out
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
playerRB.AddForce(Vector3.up, ForceMode.Impulse);
}
}
but how do i add the jump to it because it wont let me multiply the value by the jump vlaue
wdym.. its always direction * forceAmount
Wild.
the same thing you did for movement..
Vector3.up * jump, ForceMode.impulse
damn it i tried doing that earlier but not now after i fixed the second part lol
okay that makes sense
Brainfart moment. 
🥲🥲
Where did you think you should be multiplying earlier? 

Damn it🤣🤣
do you know vector math
Heck no
I found out what Vector is 2 weeks ago lol
When I watched a data structure course on YouTube
We aren’t getting to data structures until the final semester
Given the confusion earlier, I think Grade 8 physics would have helped a bit for vector math?
Isn't the first topic is about vectors are units with a direction and magnitude?

And the most common expressions are X and Y...
Damn.
As long as you're in a scientific field, you should have physics in college anyways right?
Ah ok.
Yup
I didn’t wanna take it along with calc2
Cuz that’s gonna be a nightmare I heard
🥲🥲
Our calc1 processor let us use our phones and any calculator we want during the exams lmao
It was on a pc too
And all multiple choice
Ridiculous 🤣
Idk, I legit have pre calculus have the same topic as Calc2. But our teacher decided to spam the most obscure trig and algebra properties along with it.
Woah you did integrals in pre calc??
The topic is called anti derivatives.
Yeah pretty much.
We only went through the basic essentials. Didn't go ham with trig identities back then.
Did Ur teacher forced you to memories trig identities?
Nope he let us have formulas luckily🥲
I’d have failed if not
Formulas is all I need
Double angle, half angle, cos to sin.
sin^2() + cos^2() = 1?
Not even scratching it.
Real.
I went through Calc3 while forgetting trigonometry substitution from Calc2. I am TOTALLY managing this.
Hahaha I’ve been told 3 is easier idek what they teach there
Basically, algebra, but with derivatives of y.
Also there's a shit ton of formulas.
Oh my god
Istg if they don’t allow formulas
For this semester I emailed all the professors and asked if they allow formulas lmao
You have a formula for each case.
And there's a lot of cases and you have to YOLO it sometimes.
how can i add a force in an angle? cant seem to be able to
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform player;
public Vector3 positionOffset;
public Quaternion rotationOffset;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.position = player.position + positionOffset;
transform.rotation = player.rotation + rotationOffset;
}
}
why does this not work;-;
what's your current code?
define "doesn't work"
"doesn't work" can mean a lot of things, it doesn't really give us any info
why haha
you can't add quaternions like that
void OnSprint()
{
//If on air be able to dash one time
if(isAbleToDash && !isOnGround)
{
//zoom
rb.AddRelativeForce(Vector3.forward *dashForce, ForceMode.Impulse);
isAbleToDash = false;
}
}```
do you even need a rotation offset though
yea
im trying to dash on direction of the camera
so it looks kinda down at it
ok, how exactly does this, not go in the direction you want it to?
well atleast on the angle it is at
it'll go in the direction of the GO it's on, is this script on the camera?
no its not
so what should i do in that case?
also do you want to dash up when you're pointing up? or just the direction of yaw
direction of yaw in general
then you probably wouldn't use the camera direction
huh, how so?
since then you'd be dashing into the air or the ground along with the pitch of the camera as well
(ax + by + c)dx = (ax + by + c)dy
That's a linear equation. Check if the inner equation if they are parallel or intersecting and substitute them respectively.
y'' + y' + y = 0
That's a second order linear differential equation. Let y = e^rx and substitute, solve for the constants r. There are cases each and the answer varies if they're complex, two r values, or just one.
y' + P(X)y = Q(X)
That's a first order differential equation. Use Bernoulli's equation.
x dy = y dx
That's a separable equation, move the values to the other side and integrate normally.
what's your camera/player setup
ohh ok
i dont konw if this would be related to unity but i for sm reason i cant boot up my vscode to start a new project:
error message:
Failed to find dotnet from path with "which dotnet".
Cannot find .NET SDK installation from PATH environment. C# DevKit extension would not work without a proper installation of the .NET SDK accessible through PATH environment. Rebooting might be necessary in some cases. Check the PATH environment logged in the C# DevKit logging window. In some cases, it could be affected how VS code was started.
PATH=/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:~/.dotnet/tools
Using local .NET runtime at "/Users/xin/Library/Application Support/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/8.0.11~arm64~aspnetcore/dotnet"
.NET server started and IPC established in 982ms
Completed Spawn .NET server (1675ms)
Starting Initialize template service...
Completed Initialize template service (15270ms)
Starting Initialize template service...
Completed Initialize template service (155354ms)```
wdym?
the whole code?
or the interactions between the two
what the hell am i looking at XD
no, just a description please lol
oohhhh ok
that looks horrendous
like, is the camera a child of the player or anything? do both pitch, or just the camera?
also, how exactly does that code not work?
Yeah there's just too many. Good luck when you have to deal with them.
calc3 is in bachlor's
Yep.
pain
turn ** camera** up down, turn player left right, camera is child of the player
so the player is yawing and the camera is pitching, yeah?
@wispy coral also this
camera code following an object should be in LateUpdate. the camera is trying to set its position during the same frame the object is moving to its position. there is no guarantee the object Update will run before the camera Update, therefore, placing positioning code in LateUpdate will ensure Update has been called for all GameObjects . . .
well i want to dash forwards and in the direction im looking at up down and i cant seem to add force at an angle or the direction i want
i searched camera follow unity and the guy is doing it in the update field
give an actual description of the problem please, you aren't really giving any info to work with
practice, trial and error, and i like to read . . .
im sorry
but its not the code that isnt working its just that i cant figure out how to get it to "dash" where the camera is looking at
but i can try detailing the problem more
i mean.. that's how you do it
what?
so ive been doing it correctly this whole time
the code you showed is how you'd do it
god damn it
yeah so what's the actual issue lol
it was just going forwards not up or down
i mean this would be subject to linear drag, if you want a consistent speed you might want to use a different approach
so... do you want it to?
you said you just wanted it to go in the direction of yaw 🤨
to be honest i cant differentiate yaw pitch and roll
if you want it to be subject to pitch too, then take the camera's forward direction instead of the player's, since the player doesn't pitch
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform player;
public Vector3 positionOffset;
public Quaternion rotationOffset;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void LateUpdate()
{
transform.position = player.position + positionOffset;
transform.rotation = player.rotation * rotationOffset;
}
}
the solution is to just replace the addition with multiplication???
yaw is horizontal rotation
pitch is vertical rotation
The solution I've seen in a YouTube tutorial for dash is to set the velocity every frame for the period of the dash.
Yep.
(though it should be setting the velocity every physics tick, not every frame)
Do you store the velocity before dash and reapply after?
got it, never really understood the concepts of those axis
so you'd use camera.transform.forward with AddForce instead
no, so you can redirect right after the dash
i have stiff controls
so now im using that but its now dashing in the default forward position
nvm i dont even know where its dashing now
did you do both the changes?
if you just make it AddForce, it'll be using world coords
ok got it i didnt see the other thing
im definitely sleep deprived
its like 3 am where im at
get some rest lol
so information is not getting trough rn
ill do that right after finishing this
its just too fun
relatable 
i do have a question tho, i had to use relative force to move my player but why not there?
AddForceRelative is relative to the rigidbody's rotation, which isn't pitching
you can get the same effect with AddForce by using transform.forward instead of Vector3.forward, for the transform that the rigidbody is on
that would still not be pitching, but now you can control what it's relative to by changing what transform is used
oooooh got it ok
the problem here is rotationOffset; it's a Quaternion. you don't manually set or alter a quaternion. (it doesn't behave how you think it does.) use a euler angle, Vector3 that represents a rotation to use as an offset . . .
I tried using the Euler and it compiled but then when I typed in the rotation offset of where I put the camera in the scene 9.something it messed up the entire offset
And btw i searched on google and found nothing about that solution, the only reason I know to use the Euler thing is ChatGPT but people tell me always to not use that
So idk what to do
can i update or create a prefab during run time ?
No.
what are you trying to do.
modify a boat and letting the player play with that modified boat in the next scene
Do you want to keep the changes through multiple runtime starts? So save it? A prefab is just some kind of blueprint for a gameobject, that you can spawn out of. What you are doing with that instance (hence the method instantiate) is totally runtime bound. So if you want to save it, you need to create a system that saves and loads your customisation. If its just for one shot play runtimes, you can just keep the boat changes with DontDestroyOnLoad between scenes
A preafb cant be changed in runtime, just in editor. ONly the instances can be altered
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
private Vector3 offset = new Vector3(0f, 0f, -10f);
private float smoothTime = 0.25f;
private Vector3 velocity = Vector3.zero;
[SerializeField] private Transform target;
private void Update()
{
Vector3 targetPosition = target.position + offset;
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
}
}
why doesnt the camera is not following the player?
im trying to make a script where you have to collect fuel to power the generator. the generator works the first time i collect the fuel but the second time i click on the fuel the bar doesnt apear or the fuel counter doesnt increase
please don't crosspost
mb bro
have you added the script to the camera and set the reference correctly?
also use LateUpdate for camera updates
how do i make variable for tag?
public TagUnitType BadGuy;
i want to make when player collide with gameObject that has "BadGuy" tag, die but i don't know what variable type i should add
tags are just strings
let me test it out
am i have to type the tags name for it to work?
yeah, how would it know what tag you want otherwise
it didn't work
{
if (collision.gameObject == badGuyTag)
{
}
}```
the error say "Operator '==' cannot be applied to operands of type 'GameObject' and 'string'"
yeah think about what you're trying to say there
you're asking if a gameobject is equal to a tag
that's not gonna happen, they're completely different things
a gameobject has a tag, so you would compare the tags
and there's a handy method for that, CompareTag
yeah that'd work
let me try
huh apparently there's a TagHandle type to avoid string comparisons
give that a go, maybe
oh thats cool
i was about to whine how its ass that youre forced to compare with raw strings
that's why I don't use tags for very much :p
will "scoreTable = ScoreTable.Instance;" work if the gameobjct with the singleton is deactivated?
yes
no
no?
no!
What am I missing?
2 things, think about how code runs
I mean it looks fine to me
is it th static ScoreTable declaration?
the DDOL bit probably wants to be inside the else
no, it's your awake method
do you think code stops executing just because you called Destroy?
Oh yeah that's the worst bit
no code will still run, but It said on a site gamedev somethnig you should detroy to only have one singleton
Destroy and then return
so what happens after you call Destroy?
It also doesn't have a good reason to be public
You should but personally I would get rid of Instance != this BTW since there's no scenario where the singleton will call awake again
That was in response to this
oh ok
it will continue forever?
🙃 idk
Not forever... just until the end of the function
what line of code executes after you call Destroy?
Don'tdestroyonload
right and what did you just do with this in Destroy?
destroy it
exactly so you want to DontDestroyOnLoad an object you just destroyed?
oh
no I do not
no you do not
lol
so it should be in the else statement?
Wouldn’t it only destroy itself if there’s already an instance of it?
That's what is wanted
yes
the void awake?
okay thanks 😄
so I should be able to call this using:
in another script
right?
yes
even if it is deactivated
yes
BTW you might want to change the script execution order for singletons
Sometimes I've had to set them to run awake before other scripts
(Assuming you try to refer to it in awake)
Only if you also use Awake in other scripts, Start will always run after Awake
You have to be careful with Awake. they run in different frames and Awake will run on an inactive object whereas Start wil not
It seems to work, but the score seems to only sow in Scene view and not in game view haha. So I have to troubleshoot taht
can I get the awake method to run again after a new entry has been added?
because it seems to not update the scores until after I restart the game
so I assume that is the issue
Merry Christmas btw
I was going to comment that this is wrong, because the documentation clearly states:
Unity calls Awake when an enabled script instance is being loaded.
...but the documentation is lying
specifically, Awake runs even on a disabled behaviour
It won't run if the game object is deactivated, however
steve is this true that she is saying?
highscores is a local variable to the awake method, of course it will not survive outside of that
that is correct, also what I said, Awake always runs, Start does not
oh ok
Okayy so i got this problem (big shocker)
I have tried solving it but I do not know where to look, or what I need to change.
There are 2 NPCs (one a prefab and another a dragged and dropped copy of that prefab,) one named carl, and the other lenny. Both with a trigger that displays their own icon, and hint text (such as "press 'E' to do a thing")
However in the screenshots below, it updates (not based on the first loaded, my mistake) all at the same time
https://pastequest.com/?c1bc281ff309d6e9#G13e4cXSNkwj1XMoRF6w5YA5m6pxB1hEgfPWPLiawf26
Hopefully this is an actual issue and not me being stupid (again[again{again|again|}])
if i need to share additional info please tell me. imgoing insaene
OKAY SOOOO I serialized a gameobject variable in diatrig, put a random game object into lenny, and another into carl.
I set it to log the name of the object, and lenny logged the name of his.
But carl... CARL LOGGED LENNY'S GAME OBJECT
LENNY'S OBJECT WAS "Floor" AND CARL'S WAS "Player"
FLOOR GOT LOGGED TWICE GRAAHHHH im so close to losing it
what does "updates all at the same time" mean
im trying to make the icon appear above the NPC appear when i enter its trigger, but it makes every icon appear instead
i guess it's because of Dialog.storyIsProceeding? what is that?
variable that checks if I have pressed E to enter dialog mode. (another variable gets flipped inside diatrig, but it flips storyisproceeding in diamang. all part of my plan, honest)
it just freezes player and makes the icon(s) disappear so far
what is DiaTrig and DiaMang?
diatrig is the box around the NPC that checks if the player is inside and lets you enter dialog mode.
diamang is supposed to handle the text inside dialog mode
mang means manager like how calc means calculator
new slang
diamang works fine, its (most probably) more of an issue with diatrig and the npc prefab
I'm stupid
playerInRange was static
"mang" in thai means bug 🙃
hi, i'm trying to make a doodle jump clone and im spawning objects on top of platforms. below is the code for where im spawning the objects but the objects appear inside of the platforms instead of on top of them, why is this?
what about adding an offset value to this in your Vector3 spawnPosition?
, playformSizeY + 0.5f,
also, you dont have to fill in the last value (Z) in a 2D game, replace that Vector3 with a Vector2 if theres no need for the 3rd value
hi, sorry, i should've probably mentioned that i have 2 objects in my game. a jetpack and a spring (which is smaller than the jetpack). playformSizeY + 0.5f only fixes the jetpack's position but not the spring, thank you for the help though!
you're setting the position of the object to the top of the platform, but the position of the object is not the bottom of object
seems like your pivot is in the center, so you're putting the center of the object at the top of the platform
either offset another half of the object y size, or set the pivot of the sprite at the bottom and offset your collider accordingly
also you still have a repeated spawnedPlatform.GetComponent<SpriteRenderer>().bounds.size, you can put that in a variable
variables and functions help to reduce repetition, utilize that aspect
- float platformSizeX = spawnedPlatform.GetComponent<SpriteRenderer>().bounds.size.x / 2;
- float platformSizeY = spawnedPlatform.GetComponent<SpriteRenderer>().bounds.size.y / 2;
+ Vector2 platformSize = spawnedPlatform.GetComponent<SpriteRenderer>().bounds.size / 2;
Vector3 spawnPosition = spawnedPlatform.transform.position + new Vector3(
- Random.Range(-platformSizeX, platformSizeX),
+ Random.Range(-platformSize.x, platformSize.x),
- platformSizeY,
+ platformSize.y,
0
);
are you able to move an object with a rigid body with a characterController and still be able to use the physics?
i seem to be unable to use physics when moving with a character controller
Hello! I have created this function:
public void AddUIDocumentStyle(string gameobject_name, string element_id, string property, dynamic value)
{
UIDocument uiDocument = GameObject.Find(gameobject_name).GetComponent<UIDocument>();
var visualElement = uiDocument.rootVisualElement.Q<VisualElement>(element_id);
visualElement.style[property] = value;
}
And Unity throw me the error "Cannot apply indexing with [] to an expression of type 'IStyle'"
Someone has an idea ? ^^
how do i get the distance between 2 transforms?
It seems visualElement.style is not a collection, so you can't use [] notation to access an element of it
as far as ive heard, no, they both try to control the transform
dang, so instead how can i limit the max velocity of a rigid body?
just... set the max velocity?
Ty for ur answer! I'm really a newby with C#, how to dynamicly change visualElement.style.$my_var = X ?
huh, thanks! gotta read docs more
you typically don't
ðŸ˜
few languages have that feature tbh, where dot and bracket notation are interchangeable
the dynamic keyword is very scary there
i can only think of js
even in python it's not the default behavior
Why do you need to do this?
Are you trying to save and load styles?
in that case, simply do not do this
directly reference the property you care about
Searching for a game object by name also seems very weird
In C# for each property I need to create a function.. ?
No, you just...use the property, directly
i don't see any reason to have a function here at all
You can write a function to find a UIDocument by name, I guess
maybe just have the utility method return visualElement
but i'd advise not to hide Find inside a utility method that presumably would be used quite a bit
the entire thing smells like a bad idea to me
Not repeating each time the first 2 line + If I need to do something betwen change etc.. it's better to centrilize the function
you're trying to find a random object by name, then set a property by name
"by name" is kind of a bad idea in general
it's much easier to mess up, compared to direct references
names are brittle
apparently @swift crag knows everything ...
someone have good Jump code for 2d game?
I will be like this one day ...
{
if (isFrozen) return;
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
}```
Its my current code
step 1: yell at the computer for years and years
i'd probably just have a utility method for that visualElement line
have a UIDocument (or its owning GameObject) as an explicit reference, go through the method to get visualElement, set its style explicitly
This seems okay to me
it instantly sets your Y velocity to jumpForce
https://assetstore.unity.com/packages/3d/props/rolling-balls-sci-fi-pack-free-297168
I downloaded this asset but it is turning pink
I figured that it is only compatible to built-in pipeline, I didn't make changes to pipelines and I couldn't get it working by changing it from project settings
Anyone has any idea?
@swift crag for sure does ðŸ˜ðŸ˜ðŸ˜ðŸ˜ðŸ˜ðŸ˜
this seems fine, are you having issues with it?
What template did you use to create this project?
tip: don't spam ping random people
I'm guessing it's a 3D URP project
yes, it can be a nuisance :p
although I'm already here so it doesn't actually matter
3d ui the basic one
how do i make a rigidbody look at something
not a code question, try #💻┃unity-talk or one of the Graphics channels
i remember a function called lookat or something
oh sorry my bad
I should change the whole template to fix it or can I switch?
If my_var is a variable on style, then just like that but without the $
that's on transform, use MoveRotation
and if i want it to just look at it on the z rotation
what do i do
(or set the rotation directly)
well then do that
Rigidbody.rotation is also a quaternion you can modify
Ty! I'll do like this then, but just a last question, is it possible to "add" a function inside GameObject class directly ? So I can just do something like "mygameobject.GetVisualElement("MyID")" instead of declaring in each scripts the "Utils utils;" ?
use SetFromToRotation or SetLookRotation, perhaps
...this question sounds like you're just missing a core feature of c#
...just use static methods?
Of course, I'm a newby x)
you don't need a component or a class instance for utility methods that are just input->output
i know but what do i do after rb.rotation, i want to plug in 2 transform and make on look at the other
yeah your question doesn't really make sense lol. im just kinda guessing what you want
but only yawing, correct?
you shouldn't recreate your project from scratch, no
yes
Show me a screenshot of the "Graphics" section of the Project Settings window.
Ok so the whole "application" share all static class. I code for years 100% in JS so yes, the behavior of C# isnt intuitive for me atm but ty each day I learn new things 😄
wait did you mean rotating around y here?
I changed it to none, it worked but everything else became pink
I am talking about normal cubes even
rolling to look at something doesn't really make sense
Do not change this. You'll be breaking the rest of your materials
object look at other objet, how
you gotta work with me here...
ok sorry
you're saying it should only yaw and not pitch, correct?
i just wanaa update the orientation on the update method
z rotation is irrelevant to "look at thing"
so its immediate
You'll need to convert the materials in that asset pack to be URP-compatible. There's a conversion tool you can try -- have a look here https://docs.unity3d.com/6000.0/Documentation/Manual/urp/features/rp-converter.html
This is not a code question, so if you have more questions, they should go in #💻┃unity-talk .
(you'll just want Material Upgrade)
ok ty, will try it
how can i set a variable that i can change during an action or something but then set it back to how it was after that action?
i remember that i saw how to do it on a course but i completely forgot
@hasty dragon answer my question please
i just found what i was looking for, it was transform.lookat
no don't use that with rigidbodies
yeah i figured
just store it somewhere and restore its value
if you need to store multiple times then use a stack
thanks for your help
bro just answer the question lmao
thanks
with FromToRotation/SetFromToRotation
fromDirectionwould be the position of your objecttoDirectionwould be the position of the target, projected onto the plane that your object is on (or just set x/z equal to the object's x/z)
withLookRotation/SetLookRotationforward/viewwould be the position of the target, projected onto the plane that your object is on (or just set x/z, as described above)
the projection only applies if you don't want pitching, which is why i asked
if you want help you actually have to give information for us to help with
idk what both mean ðŸ˜
ok then say so lmao
yaw is horizontal rotation
pitch is vertical rotation
do you want make the rigidbody also rotate vertically
pitch - up-down - X axis - red
yaw - left-right - Y axis - green
roll - tilting - Z axis - blue
yeah isn't unity's coordinate system right-handed
Heya, just curious -
If a condition has multiple statements, does it keep evaluating them regardless of if it has a guaranteed outcome?
Ie
if (false && true && true) - would this stop after the first false? or would it keep going and checking the other two regardless of outcome 
I want to assume yes but i'd just like to double check
I have never heard of that before
oh wait no it's left handed
Unity uses left-handed
pretend the pitch arrow is the forward direction 😅
i think the pitch arrow is in the wrong direction
how
it should be going the opposite direction
thats not right
they short-circuit and don't check the other conditions
this is a behavior of &&/|| as operators, not conditions as a whole
Gotcha, thanks! 
it's going in the negative rotation direction
ah ok
its not working lol
then the z-rotation is in the wrong direction
it would stop if || unstead &&
how exactly isn't it working?
its just a representation of what axes are to make them more clear
kind of a nitpick at that point
if it was || it'd check the first 2
If I spawn more prefabs (bullets) how can I Individually move them how can I deal with that?
i mean.. yes that's what it is
rotations have a positive and negative direction
each bullet would have its own rigidbody or a script that handles that
they don't interfere with each other
correct, this representation is simple to just show them. All I'm saying is it isn't a big deal
the gun wouldn't be moving the bullet manually
im not saying it is, im just pointing it out lol
why the first 2 and not the first 1
|| short-circuits on true, not false
&& short-circuits on false
idk the character is not jumping
but the function is called
oh right mb
have you tried debugging? is the method being called? is the guard clause being triggered?
I tried like this
in the Shoot script
private void OnFire(InputValue inputValue)
{
if(inputValue.isPressed == true)
{
Debug.Log("FIRE!");
Bullet = Instantiate(BulletPrefab, Gun.transform.position, PlayerAim.AimTransform.rotation);
Bullet.name = BulletPrefab.name;
InitialMousePosition = PlayerCrosshair.GetMousePosition();
BulletTravel.ActivateBullet(Bullet,InitialMousePosition);
}
}
and in the BulletTravel script
private float distance;
public void ActivateBullet(GameObject Bullet,Vector3 InitialMousePosition)
{
StartCoroutine(Travel(Bullet,InitialMousePosition));
}
IEnumerator Travel(GameObject Bullet, Vector3 InitialMousePosition)
{
distance = 0.1f;
while (distance < 0.40f && Bullet != null)
{
Bullet.transform.position = Vector3.MoveTowards(Bullet.transform.position, InitialMousePosition, distance);
distance += 0.01f;
if (distance > 0.40f || Bullet.transform.position == InitialMousePosition)
{
Destroy(Bullet);
}
yield return new WaitForSeconds(0.02f);
}
if (Bullet != null)
{
Destroy(Bullet);
}
}
but it says
to this line
BulletTravel.ActivateBullet(Bullet,InitialMousePosition);
why?
BulletTravel is null, i guess
BulletTravel is the script thats in the bulletprefab
how can it be null if 2 lines above I Instantiate the bullet prefab
ðŸ˜
im not really getting the hang of this 
Is it possible to get all the assets in an addressable asset group?
don't use PascalCase for variables, that's just confusing lol
oh ok
how's that related
what even is BulletTravel
is the script inside the bullet prefab
you haven't shown how it's defined, and you're mixing cases so i don't even know if it's a type or a variable
BulletTravel should make the bullet move when spawned
is it a variable or a class
class
so ActivateBullet is a static method on that class?
yes
umm not really
yeah so static doesn't really make sense here
wait i didn't read the full snippet
ActivateBullet is not a static method there
why would you say it was 🤨
i was confuse too sorry
....BulletTravel is a variable, isn't it
no its a full script
you've just named it the same thing as the class because you're using PascalCase where you should be using camelCase
then BulletTravel.ActivateBullet wouldn't be valid
you have it as a variable and you have not set it
I used this
[SerializeField] private BulletTravel BulletTravel;
exactly, it's a variable there
but that doesn't really make sense
if BulletTravel is on each bullet, why should it take a specific gameobject for a random bullet?
oh
why would it be managed centrally?
ugh Im trying to make the bullet just move after it is being spawned
but i guess its not right
ActivateBullet and Travel just need to take in initialMousePosition, since it would just be moving the bullet that the component is on
and then you would trigger ActivateBullet on the bullet that youve created, not some random detached BulletTravel
i think you need to step back and think about the flow of logic here
so I creat the bullet
which is Bullet
and I want to somehow call the script thats in the bullet to make it move after being spawned
actually first off go and fix your casing so you aren't shadowing random stuff and confusing classes with variables
that's doing you no favors
so how to use cases corect
wich case for class and which for variable
camel case for variables?
yeah
ight
Hi someone know why my character is not jumping? (Jump function i called)
https://pastequest.com/?120efa8841aacc1b#8QdtHLptwgmfTZ2fvctFQwAE9sk3agpzR5zr5akN8vwx
you're resetting the velocity in FixedUpdate
the default force mode for AddForce is meant to be a continuous force
you need to preserve the y velocity
i.e. you call it every FixedUpdate -- do this instead
rb.AddForce(Vector2.up * jumpForce, ForceMode.Impulse);
you were also using the current X velocity for some reason
don't do that; just apply a force straight up
Also, yes, the more pressing problem was that you immediately set your own velocity, which completely overrides the force you added
can i get the script component of a game object?
yes, GetComponent
ok but how is the component name the scripts name?
...what?
you set it
that's kinda how c# works
the actual name of the file isn't important here, what's important is the name of the class
though with your case, you could just make bullet typed as BulletTravel instead of GameObject, then the value you get back from Instantiate would be the BulletTravel you could call Activate on
how can i remove the maxLinearVelocity on an rb?
i did the camel case and tried like this
you can't, it's a property of the class
do you mean removing the restriction?
exactly that sorry
probably set it to infinity
alright
btw the == true is unnecessary
ok
also bullet could probably be a local variable instsead of a class variable
and also this
im pretty sure bullet.name = bulletPrefab.name is unnecessary, it'll already have that name
no it wont, it will have (clone) appended
ah, right
@naive pawn @swift crag Thank you!
if (!pair.Value.Element)
{
Button compound = Instantiate(compoundButton);
compound.gameObject.SetActive(true);
compound.name = pair.Key;
compound.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = pair.Key;
compound.transform.SetParent(content.transform);
compound.transform.position = new Vector2(0, y);
y = y + 40;
}```
The position of the instantiated object should be 0, 0 (initial y value = 0)
Meanwhile the button in question:
like what
is there a way to set a rigid bodies max velocity on select axis? tried just setting a max speed but moving while in the air made it impossible to fall
i think you'd just have to clamp it yourself for that level of control
every fixedupdate
dang it, how might i be able to do that
hello every one
i am wondring how can i check if unity and cs code are working together cz i feel like they aren't
with mathf?
yeah
math is too much for me
here's the general way to do it!
unity runs on cs, it can't "not work together"
if there's something not working related to code then it's an issue of the code
there's literally no math involved
but its with the mathf thing no?
idk it doesn't auto complete more than half the stuff
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
thx
it does the math for you, you don't have to do any
Vector3 targetAxis = Vector3.up;
Vector3 original = rb.velocity;
Vector3 aligned = Vector3.Project(original, targetAxis);
Vector3 remainder = Vector3.ProjectOnPlane(original, targetAxis);
aligned = Vector3.ClampMagnitude(aligned, 10);
Vector3 result = aligned + remainder;
alright i see
Take the original vector. Split it into two pieces:
- The part that lines up with your axis
- The part that doesn't
Do whatever you want to those two parts, then put them back together
now that, that's math
This works for any direction, not just cardinal directions
thanks so much fr
I try to avoid touching specific vector components whenever I can
so that my code winds up working even if gravity is going, say, 30 degrees to the left
and the player is spinning like a top
[SerializeField] Vector3 maxSpeeds;
Rigidbody rigidbody;
void FixedUpdate() {
Vector3 vel = rigidbody.linearVelocity;
vel.x = Mathf.Clamp(vel.x, -maxSpeed.x, maxSpeed.x);
// repeat for y & z
rigidbody.linearVelocity = vel;
}
this is like, the basic way to do it
just as an example
thanks also
i'd recommend a general solution like fen's
ill try both and see which one works better for me and which one i truly understand
i can't say i recommend fen's directly since it's too late for me to understand any math lmao 
oh hi fen
lmao get some rest
same thing as before
(something like this would work fine for like, vertical axis only, given that the rb doesn't rotate and have wonky handling in that case)
i see, ill note it down
a similar idea would be fine for horizontal only, with the same restriction
got it
honestly physics based movement is just so cool but its too much work
some parts are simpler
other
not so much
how come when using Unity netcore, if I start an instance of the game as the host, and then move to the top left corner, and on my clone of the game I join as a client, itll spawn the character in where the host left off but there is only one player on the screen? shouldn't there be two?
does impulse force mode apply force everytime or just once when using update
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform player;
public Vector3 positionOffset;
public Vector3 rotationOffset;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void LateUpdate()
{
transform.position = player.position + positionOffset;
transform.rotation = Quaternion.Euler(rotationOffset) * player.rotation;
}
}
this code looks correct right?
hey molt haha
wassup
just woke up straight into coding lol
thats great same thing here
use addon , more easier
what is addon?
obligatory: use cinemachine
i use cinemachine for 2D , but i dont have how it works in 3D
cinemachine would be good but you can easily make one via scripts
i was trying to via a script but it doesnt really work
the rotation calculation messed it up
i want to achieve it via script so i learn too haha
wait nvm it does work i just had to put different numbers for some reason
i thought i could just copy paste the offset from where i positioned the camera already in the scene behind the player
Is there a difference in DontDestroyOnLoad(this) and DontDestroyOnLoad(gameObject)?
Someone know why i cant jump?
{
if (IsGrounded())
{
rb.AddForce(new Vector2(0, jumpForce), ForceMode2D.Impulse);
highestJumpY = transform.position.y;
isJumping = true; // Mark as jumping
animator.SetBool("IsJumping", true);
}
}
private bool IsGrounded()
{
return Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, groundLayer);
}```
What is groundLayer?
this works only for the object which has the scrpit , but you can acsess from any object to another with using game object
You should add a few log statements to check if Jump is running at all and if IsGrounded is returning true
This is the layer I defined so that the player can recognize the ground
idk bro its script from google
@swift crag there is the full script
https://pastequest.com/?f3fd1eee215ad041#3RQQT61eXdtYYqUPrNNhRd1ri48LW9MwrbD9rgDiE4DB
how can i make counter movement with a rigidbody so i dont go slip and sliding when ever i release WASD
can someone help me understand where this error is coming from
im guessing something here is wrong for my player prefab?
hi everyone, anyone has experience with dotween?
using UnityEngine;
using DG.Tweening;
public class PauseController : MonoBehaviour
{
[SerializeField] private GameObject pausePanel;
[SerializeField] private GameObject blockingPanel;
[SerializeField] private float animationDuration = 0.5f;
private bool isPaused = false;
private RectTransform pausePanelRect;
private Vector3 originalScale;
void Start()
{
pausePanelRect = pausePanel.GetComponent<RectTransform>();
originalScale = pausePanelRect.localScale;
pausePanelRect.localScale = Vector3.zero;
pausePanel.SetActive(false);
blockingPanel.SetActive(false);
}
public void OnPauseButtonPressed()
{
isPaused = true;
Time.timeScale = 0f;
pausePanel.SetActive(true);
blockingPanel.SetActive(true);
pausePanelRect.DOScale(originalScale, animationDuration)
.SetEase(Ease.OutBack)
.SetUpdate(true)
.OnComplete(() =>
{
Time.timeScale = 0f;
});
}
public void OnCloseButtonPressed()
{
isPaused = false;
pausePanelRect.DOScale(Vector3.zero, animationDuration)
.SetEase(Ease.InBack)
.SetUpdate(true)
.OnComplete(() =>
{
pausePanel.SetActive(false);
blockingPanel.SetActive(false);
Time.timeScale = 1f;
});
}
}
the first time i enter in play mode, i click pause button, time scale goes to 0, but nothing shows then if i press again pause button the pause panel shows without animation, then if i unpause and pause again, everything works as it should
i also tried to call init method in start but it doesnt help
can't find the option of the "quiz script" in the function list even though the script is added to the canvas as a component
Show the inspector for the "quizCanvas" object
This indicates that Unity is having a problem importing your script
Do you have any errors in the console right now?
hit "Clear" to remove anything that isn't a compile error
CS0246 this bad boy who won't leave me alone
Is your code editor not showing you any errors right now?
If so, you need to fix that first.
make sure your !IDE is configured so you don't make silly spelling mistakes like that
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
I TRIED LIKE 1000 TIMES ALREADY IT JUST DON'T WANNA WORK
mb all caps
Screenshot your entire code editor window for me.
do you not see sprite is underlined?
im following a tut on udemy and for the guy it just worked
he spelt it correctly
because the guy in the tutorial spelled it correctly
im sure im missing somthing
ah i see
yes, you're missing the correct spelling
C# doesn't care if you wrote Sprote or sprite or Psrite
none of these are exactly Sprite
i seeeeeeeeeeeeeeeee
Generally, type names are PascalCased
and before anyone points out "int, string, float" etc not being PascalCase, those aren't actually the type names, those are aliases
anyone?
look dm
I'm trying to load my UI toolkit from addressables: Addressables.LoadAssetAsync<VisualTreeAsset>(assetAddress + ".uxml"); ... but it can't find it, also tried without the .uxml. I also tried having simplified names etc. but it just can't find it
And the report says it's in there
Is ded
not how discord works. ask your question in the appropriate channel and when someone who is familiar with the topic sees it they can answer it. otherwise you're just creating noise in unrelated channels and your question ends up getting drown out by other questions
you don't want me trying to answer your addressable questions in here 😄
(i will do a terrible job)
alright so i'm trying to make a 2d gun that has a massive recoil that knocks the player backwards when you fire it, and the vertical knockback is completely fine but for some reason there is no horizontal knockback at all, it is super weird
the code is here https://hastebin.com/share/dasaxisopo.csharp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
I thought they were camel case
Or all lower case
I guess just primitives are
you're very likely overwriting the force applied in your component that handles movement by assigning velocity based on input. if you want knockback to work you either need to temporarily stop assigning the velocity or use forces to move the player
indeed, the proper name for float would be System.Single, for example
convenience, I suppose
What is the purpose of abstracting a primitive data type to the same thing with a dif name lol
why do we give multiple names to things?
Just sounds like purposely reducing performance
what, you mean that the current code will not knock the player back horizontally if my player movement script uses velocity to change its position?
this has zero bearing on performance
it's just a global alias so you don't need the System using directive in every single file
Instead of just using a native primitive type, it has to search for the module, then load the module and use it
what
right, if you are assigning the velocity each frame then your knockback force is just being overwritten because you are just directly assigning the velocity instead
you're just making this up
ughhh is there an alternative to forces when it comes to these kinds of knockbacks?
Nevermind lol, I have no idea what this system. Stuff is
hi guys
One option is to store a separate "knockback velocity"
HAPPY christmas everyone
Sum it up with your desired velocity, and have it quickly return to zero over time
System is just a namespace . . .
aight i'll try that
Ah
and System.Single is a struct called Single that is within the System namespace. float is just an alias for that. much like Applied_Algorithms is an alias for you, if i were to say "tell Applied_Algorithms about namespaces" it would be clear I was referring to you, but that's not your actual name, just like float isn't System.Single's actual name
you can also set up your own local aliases with a using directive, it has no impact on performance, it just allows you to refer to a type using a different name. this is a common solution when attempting to use the Random class when both the UnityEngine and System using directives exist in a file.
you can also add global aliases in C# 10 the same way (but just adding the global modifier) but unity doesn't support that yet
i can't wait to see what kinds of insane problems people manage to cause with that 
global using var = System.Dynamic; 
fortunately that doesn't exist
how can i do X animation when state is 4
dynamic just means System.Object with special treatment
You can't check for equality with a float parameter
If you want a bunch of numbered states, consider using an int parameter
i just have basic anims
you should be using a blend tree for things like this
whats that
It lets you pick from many animations based on one or two parameters.
and in 3D (or whenever you're doing bone animation, really), it smoothly blends between the animations
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
How would i go about applying force to an object through the direction of a raycast? currently i have a script that applies the force in the "normal" of the object but it doesnt have the physics i want
presumably you already know the direction of the raycast!
Perhaps you're asking how to apply the force at a specific point on the object, instead of its center of mass?
There's a method for that -- https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Rigidbody.AddForceAtPosition.html
that'll make an object tip over if you push on its top, for example
now add two parameters for "X movement" and "Y movement"
and pick them in the blend tree's inspector
(you're just using "state" twice at the moment)
wont that try and use two animations at the same time? both X and Y
A 2D blend tree uses two parameters to decide which animation to play
It blends between them based on how close they are to the parameter values
ah i see
oh thats much simpler than I thought it would be
appreciate it
this is the current code that i have
RaycastHit ray;
Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out ray, 5f);
ray.rigidbody.AddForceAtPosition(-ray.normal * hitForce, ray.point, ForceMode.Impulse);
its still seems to apply force at the normal
well, yes, you're using -ray.normal as the force direction
don't do that
also, your code doesn't check if the raycast missed
Ray ray = new Ray(fpsCam.transform.position, fpsCam.transform.forward);
if (Physics.Raycast(ray, out var hit, 5f)) {
// ...
}
I like to construct a separate Ray to declutter the raycast call
and you can declare the RaycastHit variable as you call the method
you also need to check if the thing you hit has a rigidbody
it might just be a static collider
(by "Static collider" here I mean any collider that isn't attached to a rigidbody)
I guess that...kind of works
But why not just use a 2D blend tree? You have an X direction and a Y direction
this seems like a very obvious place to use two parameters
i find this more simple and easy to use
im not animating anything big
althou
still thats it? do i need to do anything more
for some reason animation still isnt working correctly
Do you ever set the animator parameter anywhere?
Can I write my own server in c++ that interprets data from unity cient and sends it over a network?
Why are you using a 1D Blend Tree for two dimensional movement?
You can do whatever you want outside of Unity
Im just wondering how I would get output from unity into a different file
from a unity client
if both can work why not?
you can beat nails with a wrench
but it's not a great experience
It's going to be blending animations based on the value between your defined endpoints, and you're probably getting incorrect blending leading the animation not playing
I just heard there's a lot of networking issues with unity's built in networking, so I wanted to make my own
alight then ill use 2d
Then the code becomes incredibly simple. You just pass the X and Y inputs into the animator
Im just wondering how I can output to a file in unity
Same way you would in C#, you can use all System.IO functionality you want in Unity
oh lol, thanks
A lot of stuff is just "however you'd normally do it"
The main differences are when you want to interact with Unity objects
(e.g. you must be on the main thread)
I always think theres some specia way to do things in unity, but sometimes there isnt
unity has much less power over your code than you might think!
I used to be stuck in that line of thinking
notably, I thought that it somehow turned my references into null with Magic Powers
(no, that's just a custom equality operator on UnityEngine.Object
it just sets them to null?
lol im not experienced enough in unity to understand that xdD
Ive written a few client and server programs in python, I think I should be able to do this i c++
Your blend tree appears to use the state parameter that doesn't exist
If those are the parameters you want to use for X and Y
I'm wondering if should make the server literally just a separate program, then make some logic in unity that searches for it's ip address and port, so the server logic is completely separate from the unity project. Doe that sound like a normal thing to do? lol
X and Y are not floats
where can i change that?
You should consider reading the error messages
Im just wondering how I would do additional checking of the gamestate on the server
Where you made the parameters
When you destroy a Unity object, it starts comparing equal to null. This makes it look like Unity has somehow reached in and overwritten your variables
i did actually but i am sending these because i do not know how to fix those
oh weird haha
i have it in script and this animator window
summoned as float in the script
oh my bad I just saw the networking thread
i fixed it
You created the "X" and "Y" parameters as integer parameters, not float parameters.
They look identical in the parameter list, which is a nuisance
yeah i did
but animation is still not working
character is only playing upwards walk animation
Do you ever actually transition into the blend tree in the animator
Walk up is your entry state, and nothing ever exits it
So why would you expect it to ever do anything else
Transitions out of the Entry state are only considered when you start the animator
or when you go into Exit
notably, this means you are stuck in "walk up" forever
also, if you leave Blend Tree for any reason, you'll never get back, ever
Why do you have both?
Doesn't the blend tree handle your directional animations?
if (doorToggled == false){
doorToggled = true;
} else {
doorToggled = false;
}
if (doorToggled){
float currentRot = 0;
// Set adjusted correct angles.
if (currentRotEuler.y <= 90 && currentRotEuler.y >= 0){
currentRot = 180;
} else if (currentRotEuler.y <= 180 && currentRotEuler.y >= 90) {
currentRot = 270;
} else if (currentRotEuler.y <= 270 && currentRotEuler.y >= 180) {
currentRot = 360;
} else if (currentRotEuler.y <= 360 && currentRotEuler.y >= 270) {
currentRot = 90;
}
transform.rotation = Quaternion.Euler(0, currentRot, 0);
} else {
transform.rotation = Quaternion.Euler(0, currentRotEuler.y, 0);
}
}``` why door no move
Debug it. Add logs in every if and else statement and print out the condition related variables to see if the code executes how you expect.
kk thanks!
do I have to have the transform.rotation within an update?
the method is called within an update in another script already
I have an issue that I'm really unsure about how to solve. This is for a school project and I'm still very new to Unity. The project is that you drive a car around a terrain and pass through Waypoints, where the goal is to not run out of time. Every time you pass through a Waypoint, that Waypoint moves itself to a random position and 10 seconds gets added to the timer.
I have a spawn manager script, WaypointSpawnManager, that I've realized is unnecessary, but anyway, it spawns Waypoints by calling the WaypointScript's Spawn method. This method instantiates a new Waypoint ten times. This Waypoint is a prefab that I have dragged out and hidden in the game somewhere, and it has a component of itself and the GameObject that houses my Timer script. These Waypoints have an OnTriggerEnter method, where each time the player collides with one, the Waypoint in collision moves to a random position and adds 10 seconds to its Timer component, which is the one, singular Timer GameObject in my scene.
My issue is that the collided Waypoint randomly moves to a position like it should, but 10, 20, or 30 seconds is added to the timer, nothing more, nothing less and I'm very unsure as to why
WaypointScript hastebin link: https://hastebin.com/share/opemapibix.csharp
Forgot to mention that for debugging, I'm not sure how I would fully debug this, so I've driven my car slowly to see if it was colliding with the same Waypoint multiple times. It still randomly added either of those times. I've checked the coordinates of each Waypoint to see if it was colliding with another Waypoint when it randomly changes its position, but it's too fast for me to check that
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
If you want the logic to run on every frame, yes. But if it's called from a method that is called from update, then it's basically the same. Unless there's some condition along the way that prevents it from running every frame.
The most basic way to debug something in unity is to use Debug.Log to log something in the console. In your case you can put a debug log in the OnTriggerEnter method and log this object and the one colliding with it. That would help confirm that the issue is with the collisions and not somewhere else in your code.
Refer to the documentation yo learn how to use Debug.Log.
alright, thank you
omg it's how the free car asset I downloaded was put together. The waypoint detects one, two, or all of its SportCar prefab, Body GameObject, or its own Collider GameObject. Body is a child of SportCar and Collider is a child of Body. Do you know how I should deal with that so only one...thing...is being detected for collision? I have no clue what to do with something like that. Are there any kind of images that I should send as well?
Hey, I know there is a lot of people saying "GetComponent" is really bad since time spent loading, what are other methods that you can use? Example, trying to get my script to look into another script to find a value, what would you use for that?
we had to choose free assets or model our own (I can't do the modelling option) for the project
You would use GetComponent.
Ohhh okay. Thank you!
The simplest way I can think of is to deactivate the waypoint immediately after the first collision. This way it wouldn't collide with anything else. I think.
I think I can think of a way about how to do that, thanks!
how can i make a rigid body go up damn stairs
use a ramp shaped collider instead of stair shaped collider
if i used probuilder how can i change the mesh collider?
use a different mesh for the collider
As always, you can freely assign the mesh that MeshCollider uses.
didnt know, thanks!
Thank you!!!!
why is renderer and collider bounds.max not giving the top point on the mesh or collider?
Vector3 topPoint = GetComponent<Renderer>().bounds.max;
Debug.DrawRay(topPoint, transform.up * 100f, Color.yellow);
because bounds is an AABB
and not the actual collider itself
is there any way to get the point without calculations
Put an empty GameObject there
and use its position
