#💻┃code-beginner
1 messages · Page 318 of 1
This part is just as important. Make sure everything is arranged and assigned correctly
{
if (lfAngle < -360f) lfAngle += 360f;
if (lfAngle > 360f) lfAngle -= 360f;
return Mathf.Clamp(lfAngle, lfMin, lfMax);
}
private void CameraRotation()
{
//targetRotation = Mathf.Atan2(inputVector.x, inputVector.y) * Mathf.Rad2Deg + _mainCamera.transform.eulerAngles.y;
//float rotation = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetRotation);
if (cameraInputVector.sqrMagnitude >= 0.01f)
{
_cinemachineTargetYaw += cameraInputVector.x;
_cinemachineTargetPitch += cameraInputVector.y;
}
_cinemachineTargetYaw = ClampAngle(cameraInputVector.x, float.MinValue, float.MaxValue);
_cinemachineTargetPitch = ClampAngle(cameraInputVector.y, BottomClamp, TopClamp);
CinemachineCameraTarget.transform.rotation = Quaternion.Euler(_cinemachineTargetPitch, _cinemachineTargetYaw, 0.0f);
}```
I'm trying to copy the code over from the 3rd person asset to create a 3rd person camera
but instead of working it caused my camera to be stuck in its original position
what did I do wrong?
i was looking for a not instantaneus rotation but does like keep the object rotating afterwars
Everything is an "instantaneous" rotation on a per-frame basis
you make gradual rotations by doing lots of small instantaneous rotations, one per frame
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
So I am using this validate method to determine if one of my moves is valid, but it only seems to work if I hover over what I presume to be the last movement in the list of movements, and it highlights all of the movements as opposed to the valid movement
https://gdl.space/ijiwuniduq.cs
It recognizes each movement so it's most probably just the structure of when I chang ethe color of the pieces
you should begin by stating what is exactly wrong before I click it
basicly my Dash() function is not being called out
have you debugged and logged your values / checked ?
like dashcount amount etc.
also gotta check what is value of dashCD1,dashCD2 etc..
yes
//counter
if (dashcount == 2 && dashCD1 == true)
{
DashChance1.interactable = false;
dashcount--;
Dash();
pm.Dashing = true;
dashcount -= 1;
dashCD1 = false;
Debug.Log("minused");
}
if (dashcount == 1 && dashCD2 == true)
{
DashChance1.interactable = false;
dashcount--;
Dash();
pm.Dashing = true;
dashcount -= 1;
dashCD2 = false;
Debug.Log("minused");
}
}
not getting call
don't use the same debug.log for 2 different if statements
and make sure your testing outside of those if statements if dashcount and dashCD1 end up in a different configuration like (0,0), (1,3) (3,1) or something like that
Then neither of the conditions required to call Dash() are true. dashcount == 2 && dashCD1 is false, and dashcount == 1 && dashCD2 is false. Try logging those values to see what they are
sorry i am new wdym by logging
debug.log
ok
you can turn variable values into strings so that you can read values at runtime in the console
i will try that
that's not limited to strings
**objects
this is what i got
Okay, so both of those dashCDs are false, so of course it's not calling Dash anywhere
i do get the fallse from both DashCD
ok
so do i just go and do
public bool DashDc = true;?
for both
why do you put that variable if ur just gonna set it true in inspector
what is literally the point of that variable 🤔
Well, you're starting a timer to set them to true, and if that's not happening, you need to find out either why it's not finishing those invokes or where else it's setting it to false
because solely based off of the tiny window into your code you've provided, they should become true after 3 seconds
if (dashCD1 == false)
{
Invoke("Dash1", 3);
DashChance1.interactable = true;
}
if (dashCD2 == false)
{
Invoke("Dash2", 3);
DashChance2.interactable = true;
}
}
`private void Dash1()`
`{`
dashCD1 = true;
}
private void Dash2()
{
dashCD2 = true;
}
this is what i did for the variable
https://gdl.space/wosebudomu.cs
my full code
if you don't ever press the dash key, do you ever see either of those CD variables log true
https://gdl.space/arikosanig.cs
This is my entire chesspiece code, the ValidateMove(Vector3Int attempt) method is making all objects green when I am hovering over the last move in my basicHexMoves array, because it logs seeing all of the valid moves but overwrites them back to white
they still come false
they came like this after spamming
but the number never got minused
how ?
Change your logs to something easier to read:
Debug.Log($"{gameObject.name} - Dashcount: {dashcount}, CD1: {dashCD1}, CD2: {dashCD2}");
Now you can know for sure which ones are true and false
Where do you set userWizard
after spamming
Okay, and does it ever come out with True, True
yes
using UnityEngine;
using UnityEngine.UI;
public class playerController : MonoBehaviour
{
public float speed = 5f;
public WizardActions userWizard;
Okay and where do you set userWizard
but i have to press a key to make it true from false otherwise it never starts as true
fixed that
by making the values true in inspector
but still the same bug
Okay, so, when they're both true, hit the dash button. Do you get the log from inside one of those conditions?
Again, after both say True, hit dash.
Does your "minused" log appear
Can you show a screenshot of your entire console window, after the logs start saying true, true and you've hit the dash button
ok
make sure to include the corner that shows the message counts and settings
gimme a minute
https://gdl.space/lonayariwo (hope link will work)
I have this code that being used in CodeMonkey's tutorial on field of view simulation with generated mesh as a mask (quality of that code is questionable, but I just use it to get things done and simple testing)
And it "works" in it's core, but I have an offset that increases/decreases while player is moving because I'm using this generated mesh from tutorial as a child of a player's empty gameObject that works like eyes placement, not as individual separated gameObject, like it was in tutorial (because when I do this - it works as intendent ofc)
Funny enough I understand why it does that, but I simply can't get an idea how to prevent this offset with parenting without some convoluted substraction, lol
I've tried using Vector3.zeros as _origin, some Transform methods, etc. - it's all just make weird bugs/artifacts and not working as intendent
Pic 1 - when mesh is a child object of that eyes object and using it's transform as _origin, pic 2 - when mesh is separated and eyes object is set through inspector and _origin is it's position
yeah, thanks, fixed the link
after i hit the dash button
So it's simply a constant offset being applied to the Mesh when it's a child of the GameObject?
yeap
In this case you wouldn't need to add an offset, as its start position is already the position of that parent object
Okay so you remember when I said to send:
- The whole log including the top corner
- After it says True, True
Also, scroll to the bottom so it's showing the most recent messages
Okay, good. I wanted to make sure errors weren't hidden and collapse was off. I'm assuming that CD1 is becoming false after you hit the dash button, which would imply that it is now working
You can comment out that log and see if you get any of your other logs when you enter one of those conditions
see if it ever prints your "minused" log
ok ima try that
thats the problem
now it prints minused
what do you think the soulution should be
if (dashCD1 == false)
{
Invoke("Dash1", 3);
DashChance1.interactable = true;
}
if (dashCD2 == false)
{
Invoke("Dash2", 3);
DashChance2.interactable = true;
}
i want this to work
private void Dash1()
{
dashCD1 = true;
}
private void Dash2()
{
dashCD2 = true;
}
And why do you think it doesn't
cuz i remove my dash to false and then it just stays true
Well, if you remove the thing that sets it to false, it would no longer become false. That makes sense.
Why would it not?
I have no idea what this is
dashCD in ui
At no point in any of the discussions we've been having have you ever mentioned anything related to UI
Well, every frame that the boolean is false, you start up a new timer that sets it to true 3 seconds later. Meaning once the first one's time is up, you have 3 seconds of queued "true"s to burn through before it can ever become false again
Maybe instead of starting the timer every frame it's false, you start the timer once when the value becomes false
how do i do that ?
So I tried logging the indices of the moves that get colored correctly, and my king with 12 files only gets colored green on file 10 (index 9)
queen is colored on file 12 (index 11)
my knight is colored on file 12 (index 11) as well
My pawn with one move technically works fin since it only has one move (index 0)
My rook is colored on move 12 of file 6 (index 5, 11)
Actually, one of my other rooks gets colored at index (5,10)
and another knight logs at (9,0)
By colored correctly I mean that the entire thing turns green on those moves and not the others
I still need it to color them individually as needed
I have problem because my character in my 2D game doesn't jump when I press the space key, my jump system works but the character dosn't take account if I press jump key more time
Very confusing. I can't figure out if your jump works or not.
my character in my 2D game doesn't jump
my jump system works
my jump work
What are you actually asking
your jump works but it doesnt jump?
it doesn't jump if i press more time the jump key
show the code and describe the issue, because we still cannot understand what's wrong
and what is the desired behaviour
Is it supposed to? Explain what you want and what's actually happening.
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
I want my character jump if i press the jump key more time, but actually my character jump when he wants
you should not be reading input in FixedUpdate
Input.GetButtonDown in FixedUpdate is 🚫
input handling belongs in Update
So ok I just follow thetutorial for see if it works but I never used FixeUpdate before
thanks I will try it
Yes I will never used fixeUpdate again because it not woks correctly
thanks @wintry quarry
this is not what you should take away from here
Input handling goes in Update
Phyics code goes in FixedUpdate
Ok just like for movements
Hello
Hi
why?
vscode has c# and unity extensions
!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
• Other/None
Becuase I'm not encoding my code
"Encoding"?
oh ok
Writing them on my mind
you aren't supposed to encode your code
you just want to write your code on VS Code ?
I just sent you a guide to configure your ide
!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
• Other/None
But in VS Code everything on my mind
We have no clue what that means.
Do the guide, then come back
Thank you
Anyone could help me with my script?
So i got this GameObject called FacilityDoor. Inside it i got 2 3D objects called FacilityDoor1 and FacilityDoor2.
Now i want the door to open when i click the door so i was working on this script but for some reason it doesnt work. Could anyone tell me why?
Both scripts under.
FacilityDoorScript.cs
public class FacilityDoorScript : MonoBehaviour
{
[SerializeField] private float rayLength = 5f;
[SerializeField] private KeyCode openDoorKey = KeyCode.E;
private void Update()
{
if (Input.GetKeyDown(openDoorKey))
{
RaycastHit hit;
Vector3 fwd = transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(transform.position, fwd, out hit, rayLength))
{
FacilityDoorController FacilityDoorController = hit.collider.GetComponent<FacilityDoorController>();
if (FacilityDoorController != null)
{
FacilityDoorController.dooropen();
}
}
}
}
}
FacilityDoorController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FacilityDoorController : MonoBehaviour
{
private bool DoorOpen = false;
public GameObject door1;
public GameObject door2;
private void Awake()
{
}
public void dooropen()
{
Destroy(door1);
}
public void doorclose()
{
}
}
both are attached to the FacilityDoor1 in the GameObject, inspector and on GameObject 1 field the FacilityDoor1 is placed
What does "it doesn't work" mean?
So if you look at FacilityDoorController.cs , the second script to test it out i wanted the door to be destroyed. Althought for some reason even when dooropen() void is triggered nothing happens
alaso instead of Vector3 fwd = transform.TransformDirection(Vector3.forward) you can just use transform.forward
My bad i forgot to mention that
Is the code even running?
You need to use Debug.Log to check
you should also make sure your console window is open
Like Debug.Log("") ?
With an actual message of course
Yes alright ill check
Debug.Log("This is the DoorOpen function!");```
Give me a second ill check, there were no errors in the console so i thought that means that the code works fine
obviously the code doesn't work fine if it's not doing what you want it to do.
that would be the opposite of "working fine"
It does. With no errors, the code is doing exactly what you tell it to do. You just told it to do the wrong thing.
on FacilityDoorController Awake works since it sends out message but when i click on the door nothing happens. It doesnt debug or anything so the problem lays withing the FacilityDoorScript then?
well where did you put your logs?
wdym
There is a location that you write code.
It would be in some method. Between some lines
Where is that location
I recommend something like this:
if (Physics.Raycast(transform.position, fwd, out hit, rayLength))
{
Debug.Log($"The raycast hit {hit.collider.name}");
FacilityDoorController FacilityDoorController = hit.collider.GetComponent<FacilityDoorController>();
if (FacilityDoorController != null)
{
Debug.Log($"{hit.collider.name} had a FacilityDoorController!");
FacilityDoorController.dooropen();
}
else {
Debug.Log($"{hit.collider.name} did NOT have a FacilityDoorController!");
}
}
else {
Debug.Log("The raycast didn't hit anything");
}```
now you can actually know what's going on.
Alright thank you, ill check
I still dont understand
We expected an answer like "I put it right before the raycast if statement" or just showing the code with the logs in it to explain where the logs are
I don't really understand what part you are not getting
If I write this:
public void Start() {
Debug.Log("something");
}
And someone asked where I put the log, I would say "I put it in start"
Oh like that
No debug or anything is comming from the script. The only one im getting is from Awake().
I got a box collider on the door, isTrigger enabled. So i dont know what could be wrong
could it be that its an child of an GameObject like i said before? Since the FacilityDoor1 in which both scripts are placed in is inside a GameObject called FacilityDoor
If you have other debug logs in the code, and they aren't printing anything, then those lines of code are not being run.
So, where are those logs you're not seeing?
And in the script its ```Hit.collider.GetComponent<FacilityDoorController>();
Shouldn it be something like getchildren or something like that since the object is a child of FacilityDoor?
could anyone tell me why my IEnumerator in one script works fine but in another script gives me the error "not all code paths return a value"
{
Debug.Log($"The raycast hit {hit.collider.name}");
FacilityDoorController FacilityDoorController = hit.collider.GetComponent<FacilityDoorController>();
if (FacilityDoorController != null)
{
Debug.Log($"{hit.collider.name} had a FacilityDoorController!");
FacilityDoorController.dooropen();
}
else {
Debug.Log($"{hit.collider.name} did NOT have a FacilityDoorController!");
}
}
else {
Debug.Log("The raycast didn't hit anything");
}
I used this one
If you are not getting any logs, then this function is not running
The second one has no yield return in every path
Probably because not all code paths return a value in the other one
ah thank you
Is your script event attached to an active object?
Yes it's attached to the FacilityDoor1 wich is inside FacilityDoor. (GameObject)
why is it attached to the door
shouldn't it be attached to your player?
Ah. im such an idiot
Now it works
bruh, sorry im new to coding and thought it was supposed to be attached to the code
but thank you so much
would these be correct for trying to get a button to store its' name on click?
could someone tell me how to make a trigger such that when the player leaves an area before a certain amount of time passes they trigger an event
In OnTriggerStay, check a bool, if it is true or false (pick one), send an event
In update, decrement a float
Also in update, if the float is below 0, set the bool to whatever you want to check
That is one way. Could use a coroutine, could do the timer in OnTriggerStay if they are in it the whole time.
or just OnTriggerExit
If you dont want to do stuff every frame in OnTriggerStay
Countdown would need to be somewhere though
Start timer on TriggerEnter
Check on TriggerExit what timer is when left
Yeah, my thinking was that they may NOT actually exit the trigger. But I guess no need to check that every frame. If OnTriggerExit isn't called, they are still in it
would people know why the function for the script is greyed out and locked to this value?
Because it's just telling you what script that is
It wouldn't make sense for it to be editable
whats up with that file name
You have a script called OnIMGClick("Image1;") !?
I don't
It says you do
oh maybe I do
haha yeah that filename is wild
the file is supposed to be buttonclickhandler though
so name your file that
That is the class name.
You named the file, you can also rename it
in unity those two must match btw
this is the class name?
thats filename
why are they different
class name is the name that is literally next to the keyword class
you tell us lol
I'm so lost haha
how do you rename the one on the side
right click? rename ?
you're renaming the filename not the class
the class is fine
its normally allowed to have different filename and class name, but in unity not so much
yeah I think I tried to do that but it doesn't copy over
oh
restarting unity fixed it
probably a local issue
wdym by "copy over"
I was gonna say, the asset on the left looked fine. That was weird
I was gonna suggest copying the code onto a new script and deleting the old one
sorry to be a bother but i'm new to unity, how do i make solid ground for 2D, I created a square as a 2D object and added a tilemap collider to it but my player just clips thru the floor
Does the PLAYER have a collider?
yes the player has both a box collider and circle collider
No
Show the editor with the player selected
for the player
for the square
this is what i mean clip through, just doesnt collide
Just to be clear. I said editor, not inspector
can you show the gizmos of the tilemap colliders
(select the Tilemap, make sure Gizmos is enabled)
Can you show the whole editor, uncropped
does it still happen if you disable the script ?
I see player script there, could be causing issues
That scale is wildly massive
also yeah lol wtf
48 meters tall
gonna take a wild guess and say groundchecks are not properly working
disabled the script and nothing happened
also is that a dynamic rigidbody ?
yes
Worried that you have a script called CharacterController, a Rigidbody, and a CharacterMovement script
Did you find the CharacterController2d script online?
yes
Is that the one you disabled?
the character controller 2d script came from online, character movement is mine
yes
So, question: Did you happen to drag this script file into a UnityEvent and then change it's .name?
Whenever anything on a canvas changes, every element on that canvas redraws. In general, anything that animates should be on its own canvas
sry , my bad
nothing there will give a performance boost, both options will degrade performance
I dunno what is going on. I would try fully removing the CharacterController, setting the scale back down to 1,1,1, and then move the character up a little to avoid starting in the ground collider
Fair point
alright let me give that a try
Show the whole editor with the ground selected
Doing nothing is always faster than doing something
Ok, that looks fine
the issue with when scale is 1 1 1 is that the camera is like this and i cannot see anything
since the character is so small
Move the camera closer and set the size smaller
is that even a tile?
What is the z position of the camera
this is because you used the MonoScript.name property and assigned it to that from the button #💻┃code-beginner message
doesnt seem thats tiles painted
how do i paint tiles? just assumed adding the collider would be enough
and it would recognise the square as the tile
You paint tiles by creating a tilepalette
nope
thats a sprite renderer, not tilemap renderer
if you want to paint tiles you need a tilemap yes
yes but ur mixing a sprite renderer with tilemap
if you were to add a box collider to ur sprite you'd probably get collisions
ah i see
okay well
the player still falls through
do i need to set one as isTrigger?
Again, no
IsTrigger means there will be no collision/it is not a physical object
oh
and did you add tilemap collider to the new tilemap

So the issue was that it was a tilemap collider but not in a grid or painted from the tilepallet?
I am not great with 2d
Seems like they Added a box at first, the name was Square still it seems
and then they probably added tilemap collider and tilemap components on it thinking it would work as part of collider
that would imply they would have removed the original box collider for making tilemap
Ah ok, and that does NOT work.
Well, thanks, now I'll know for the future.
haha yeah TIlemap is weird like that, you have to paint tiles inside of it since the tiles are not technically in the world space
oke
Materials are putting textures on the model
That is what putting a texture on a model means
ohh gotcha
what i wanna figure out is;
how do i make the zipper look.. well
more as it should?
Without knowing what it should look like I can only assume you need a material with a shader that does what you expect. This isn't code related so it is probably a question for #🔀┃art-asset-workflow , #💻┃unity-talk , or possibly #archived-shaders
alright, i'm gonna delete these messages and ask the question there if that's okay
Yes. Pick one and ask there, don't post in all three
braah no one is responding
Don't whine please
Responding on what?
womp womp
Name a more iconic duo
nuh uh
oh ok
hey guys does anyone have any tips im doing 2d top down game and i guess my default state is set to idle down because after moving when i dont press buttons character looks down. How can i make it so that the character keeps looking the way it was last moving. Example: if i press D i want it to keep looking right even after i dont touch keyboard. thank you
just don't set the state when input is zero
it will retain whatever it was
oh yeah thank you so much man 🙂
how do i make an object face another object in 2D?
Vector2 dirToObject = target.position - objectToTurn.position;
objectToTurn.right = dirToObject;```
(or possibly .up, depending on how your sprite is laid out)
oh okay
im sorry for spam but how would you recomment i do that? should i do it directly in the animator or the playermovement script
I was talking about the code
hard to say specifics without seeing what you have already
it works thank you
alright cheers i will try it out now
how do i just get a script from an object using getComponent
[SerializeField] private int enemeyPositionOne;
[SerializeField] private int enemeyPositionTwo;
[SerializeField] private int enemeyPositionThree;
public void Start()
{
enemeyPositionOne = activeBattlers.IndexOf(activeBattlers[1]);
enemeyPositionTwo = activeBattlers.IndexOf(activeBattlers[2]);
enemeyPositionThree = activeBattlers.IndexOf(activeBattlers[3]);
activeBattlersPosition.Add(enemeyPositionOne);
activeBattlersPosition.Add(enemeyPositionTwo);
activeBattlersPosition.Add(enemeyPositionThree);
}
public void RandomlyRotateCubes()
{
if (Random.value < 0.5f)
{
rotateCounterClockwise = true;
for (int i = 0; i < activeBattlers.Count; i++)
{
enemeyPositionOne+=1;
enemeyPositionTwo += 1;
enemeyPositionThree+=1;
}
StartCoroutine(rotationTriangle.RotateCubesClockwise());
}
}``` Hi need some help please. what im trying to do is set the active batters index into a list. and then when the rotate they change postion. So im trying to keep track of what player is in what postion. so player 1 = 1 player 2 = 2 and player 3 = 3. if the rotate i want to update the list in ++1 but of course there is only 3 so i want it to loop so player 1=2, player 2=3 and player 3 =1. but i dont know how to bring player 3 back down to 1. trying to almost do it like an array becuase on the last one if i did ++ that would go back to zero correct?
i cant hard code it like above becuase next time they rotate it will be player 1 = 3, player 2 = 1 player 3=2 and so on. I juat dont know how to do it
You answered your own question in your question!
I was replying to someone else
sorry
well no... because I know how to get a script using getComponent then specifying the script name, but I don't want to specify the script name and just pull the first script it sees in an object.
The first script will always be Transform
Can you back up and explain what you're trying to actually do?
Because your question/description makes little sense. What use would it be to find "the first script"?
Well In my case I would have many weapons with each of them with their own script. Meaning each script on each weapon is different. So when a weapon collides with an enemy, I want the script I have setup inside my enemy to grab the weapons script and pull the damageAmount from the weapons script.
why would a weapon have more than one weapon script on it?
they dont
each weapon only has one script
but each script has a different name respective to the weapon type
You should be using either:
- Inheritance, where all your weapons inherit from a base Weapon script
- Interfaces, where they all implement an IWeapon interface
- composition where they all just have the same Weapon script on them with different stats on it
thats what I have set up
So then what's the issue
You just do GetComponent<Weapon> or GetComponent<IWeapon> and you're done
is just that then each script on each weapon has a different name
Also which one of the three do you have set up?
Literally doesn't matter
interface
IWeapon weapon = theObject.GetComponent<IWeapon>();
float damage = weapon.DamageAmount;``` or whatever you call your damage property
this is the whole point of interfaces
so you don't have to know which IWeapon it is, you just use the interface
Yup, on the learning curve with interfaces
so in your small example shouldnt DamageAmount actually be a method?
Makes more sense as a property to me
unless you need parameters for it or something
how would that work then?
Wdym?
It would work like any property works
Not to be confused with a field of course.
Interfaces can't have fields, but they can have properties, no problem.
ok I thought they couldnt have properties so let me look into that.
There's nothing stopping interfaces from having properties
properties are really just methods anyway.
Im trying to make a turret that is two parts that rotates to face an object. I wrote some code That "works" but only for a single axis at a time (It works if the base is set to rotate and the gun isnt and vise versa). If i try enabling both at the same time it then dosent work. Also I believe there is an easer way to do what im doing because currently Im giving the boecjt a local rotation then another local rotation. (The base is has the y bool set to true and the gun has the z bool set to true)
how can i do that?
like is it a transform function?
You either rotate the Transform or the Rigidbody if you have one
if you have a Rigidbody, you should generally be using that
so like rigidbody.rotate ?
no not like that
like how
Have you tried checking the documentation for Rigidbody2D? https://docs.unity3d.com/ScriptReference/Rigidbody2D.html All of the functions and properties are there
After some more testing I found that the turret barells rotation is not set properly.
I have a problem, my autocomplete and my c# doesnt load, i cant see auto completion advice and nor can i see any other possible completion
hello, i think i got the script for dash can some of you guys can review it ?
https://gdl.space/amorobuxoh.cs <-- DashScript
make sure your !IDE is configured according to the guide below 👇
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
• Other/None
it is since i updatet sdk i think
make sure you have followed all of the steps for the guide
alr, im updating the vsc editor rn, thanks bro
well that's wrong
yeah, i know
first one here
have you regen the project files
you should not be using the visual studio code editor package at all
it is written there??
show me where you see it says to update the Visual Studio Code Editor package
yes that is the correct package. you said "vsc editor" which is visual studio code editor, notably not the same thing
mb, i also said the first thing noted up there tho
are you even using visual studio or are you using vs code
well then "the first thing noted up there" is also wrong considering the first thing noted in the bot message is for visual studio
thanks, doesnt help
you're still missing the Unity extension aren't you ? Solution explorer missing
that should install C# Devkit with it
I am not, they are not showing since i updated the sdk
regen project files
clos vscode first
how to do that
is
External Tools page where you connected Vscode in unity
am on it
ah i see it
ok so click Regen and double click a c# file from unity
uh you should not click to use C# extensions
Thank you anyways 
yes, bcs now it works
Unity plugin uses Devkit
why not
SO what happens then?
can you show which version of unity plugin you have
fuck it, if it works it works ig..

Idek myself, if it works no touch it
I tried using look at and I could get the barrel to face the target but it needed rotated 90degrees so it fit in the base properly and when I tried that it didn’t work. And every time I got to the 0 or 180 degrees is dis some weird rotation
can someone help me with my main menu please
when i press tutorial
it starts a new game
this is the code
Why does PlayGame load the scene it's already in
play game loads the correct scene
begginig is the name of the scene after
its the correct scene
thtat one workd
It loads whatever scene is currently loaded
What are you expecting to happen that isn't happening?
ok
so when i press
tutotiral
it takes me to the first scene
which is only supposed to come up
when i press new game
the tutoirla button
is supposed to load up a differe scene
but it doesn
the new game button works
So, the issue is that the tutorial button does not take you to the scene "Tutorial"?
Slow down, and only hit enter when you finish a thought
yes
Unless you're getting an error, if you call that function, you're loading the scene "Tutorial"
Whether or not you actually stay in it is a matter unrelated to what you've posted so far
Put a log before the LoadScene line. Does that log print?
all the buttons take me to the same scene
ok
nope
it doesnt come up
the log doesnt come up
Then nothing is running that function
If you put a log in that function, and that log doesn't run, then the function isn't running
Where are you trying to call that function from?
main menu script
Show
main menu script
Okay, so if you put a log in GoToNewTutorial before the load scene, and that's not logging, then this button is never clicked
Then that button is never clicked
Well, if you've shown that this button calls that function on click, and you've put a log in that function that will print something whenever the function runs, and you don't see the log, then that is 1000% inviolable proof that the button is not being clicked
So either it's not being clicked, or one of the facts above is incorrect.
The fact that it's going to a different scene seems to indicate that you're clicking on that button
i copied and pasted it
renames it
and gave it a differen location for the scene siwtch bit
to switch to a different scene
this one works
this one oesnt
Put a log in that function. Does that one print? What about when you put it in that function and try to click on what you assume is the TutorialButton? Does it print the same thing?
all of these buttons r subclasses
of the main menu
the main menu has the script
of main menu
ok
Any idea why the reference to projectilePatternParent get lost SOMETIMES after performing the attack?
doesnt show for either
Is projectilePatternParent an object in the scene or a prefab
but still works?
that means the functino isnt used at all?????????????????????????
😭 😭 😭
Show the updated !code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
It assigned a prefab, but if it is searching for something in scene that might explain that, yes
` not '
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MainMenu : MonoBehaviour
{
public void PlayGame()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); // Loads when the game starts
}
public void GoToNewGame()
{
Debug.Log("new game loaded");
SceneManager.LoadScene("Beggining"); //When New Game is pressed go to new game
}
public void GoToNewTutorial()
{
Debug.Log("tutorial loaded");
SceneManager.LoadScene("Tutorial"); //When Tutorial is pressed go to Tutorial
}
public void QuitGame()
{
Application.Quit(); //Back button for Tutorial
}
}
mb
If this file was actually saved and compiled before entering play mode, and you're not getting the new game log, then that function is not being called either
yes
im aware of that now
but why
this script is connected to the Main menu
which is the parent class to the buttons
If it's properly assigned to a prefab, then the only way the reference could be getting lost is if something changes projectilePatternParent. If that variable is public, make it a serialized private variable instead so it can't be changed by another class
Because nothing calls these functions. Since you've sent screenshots of buttons that appear to be calling these functions either:
A) The object that they are calling functions of is not this script
B) The buttons are never being clicked at all
On one of those buttons, click (once) on this object here. What highlights in the inspector?
thanks for the help bro
yes 🫡
If the facts are telling you something that makes no sense, assume the code is correct and it is the fallible human jelly brain that is the problem
yes
hey i am very new to anything related to game dev and i want to do a basic 2D game i tried making basic player movement , it works but it feels like i am on ice or in space is there any way to fix it without using linear drag?
how are you making the movement
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
float xAxis = Input.GetAxis("Horizontal");
float yAxis = Input.GetAxis("Vertical");
if(xAxis != 0){
rb.velocity = new Vector2(xAxis*Speed,rb.velocity.y);
}if(yAxis != 0){
rb.velocity = new Vector2(rb.velocity.x,yAxis*Speed);
}
use GetAxisRaw
getaxisraw will return only 0 or 1?
-1 0 1
oh ok thanks
also you can just make this all one line
you dont need either the if statements or both the velocity lines, just one is fine
i saw that when i move diagonaly if i just set its velocity both velocities will be multiplied by the speed so i will move faster then the normal speed
add the multiplication to where you set the actual float after the input
Just a quick random question that came to my mind; why is Random.insideUnitSphere a parameter and not a method? Cause it is missing the "()"
You need to normalize the input before using it in the velocity calculation
Like it is supposed to be a generated value, not a set one right? Shouldn't that be a method?
It's a property. Why did they decide to make it a property when most of the other API is a method? Go find the guy that wrote that part and ask them.😅
You can generate values with properties.
what does the .normalize do (i tired looking at the docs i didnt really understand)
It makes your vector have length/magnitude of 1
What would be the length of a diagonal of a box with sides equal 1?
sqrt(2) ?
How? Isn't that like something that needs to be changed from somewhwere else?
Which is?
google says 1.41421356237
Properties are basically getter/setter methods
If I call MyScript.myValue; the value is gonna be always the same unless something else is changing that parameter before the last call
Isn't that the same?
I am trying to put this image on my capsule, but I dont want it to fully cover the capsule. Is there a way for me to have the image show up as a square inside of the capsule?
Hey so Im wanting to add 180 degree turn animation for my player I have 2, walk turn 180 and sprint turn 180, however I cant for the life of me find a tutorial that shows how to add this logic has anyone got a recommendation for one or would anyone mind having a look at my code its a modified script of Isteps third person controller and pointing me in the right direction https://paste.ofcode.org/TrTd6WWyW293PcQVVs5V3z
Correct. So when you move diagonally, you multiply this value by speed. Understand?
Do you understand what a property is?
If myValue is a property, you can return whatever you want in it, including values you calculate inside.
I got a problem with my script. I got 3 gameObjects that I reference in this script. connection1 is the child of grabbedObject. The objective of this script is to match the position and rotation of the connection1 to connection2, but with the rotation being flipped so it sorta "mirrors" themselves. Since the grabbedObject is the parent and not the child of the connection 1, it doesnt move with it, so I do it through the script. This script should make it so the grabbedObject stays with connection1, moves its position and rotation offset (since connection1's position is offset from grabbedObject). However, it doesnt seem to work. connection1 doesnt rotate correctly and neither does the grabbedObject. Can anyone help me with this? Lmk if you dont understand what I explained.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
public class C
{
Random rnd = new();
public int NextRandom => rnd.Next(0,100);
}
just as an example
Probably via some UV mapping or shader stuff, whatever the lingo 3d artists use. Not code related unless you want to do stuff really backwards
I don't understand this. Can you just assign "new()" to a Random? And then you call that new Random to generate a integer within range ech time the parameter is called?
with solving this problem i learned what the magnitude of a vector is xD
that's just target typed new, it allows you to omit the type if the type is known. and that would be System.Random that you create instances for, UnityEngine.Random is static so you don't create an instance of it
*property not parameter
What's the difference?
Parameters are what you pass into method calls
Properties are what we are discussing
And you seem to be confusing then with member fields
I understand that I can write the code, but maybe someone else already did and also caught all the corner cases:
Is there a pooling library where I can register objects and automatically create pools for them? I don't want to have to code each pool, but instead just register a gameobject/prefab with a pool and say: create me a pool of those with a certain ID.
Aren't member fields properties?
Also, basically the member fields are just the parameters for the whole class for me XD
No.
No
private int intField;
public int IntProperty => SomeCrazyMath();
public int Method(int intParameter)
{
return SomeCrazyMath2(intParameter);
}
Understand?
Not sure if a publicly available implementation is there but ive done something similar. its pretty much just a dictionary where the key is whatever you want and the value is the object pool. Though im starting to regret it because its introduced a fair amount of unneccessary complexity.
So the only difference is that Properties can be determined by some other method straigh from the class declaration, and Parameters are just within the methods?
Why do you think it caused unnecessary complexity? I would need object pools for a ton of things: bullets, different types of explotions, audio sources when a bullet hits something, etc.
If you put it, like that, yes. That's the difference. Properties are simply syntax sugar for a method. It's the same as a method that returns the part after the arrow. You can also implement whole blocks of logic in a property. It doesn't have to call to other methods.
Anybody know why my script for detection only works sometimes? Here's the script. ```using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class CarTrigger : MonoBehaviour
{
public GameObject[] InteractText;
public string sceneName;
public bool inTrigger = false;
private void OnTriggerEnter(Collider other)
{
InteractText[0].SetActive(true);
Debug.Log("Enter");
inTrigger = true;
}
private void OnTriggerExit(Collider other)
{
InteractText[0].SetActive(false);
Debug.Log("Exit");
inTrigger = false;
}
void Update()
{
if (InteractText[0].activeSelf == true && inTrigger == true)
{
if (Input.GetKey(KeyCode.E))
{
SceneManager.LoadScene(sceneName);
}
}
}
}
The property below is gonna be converted to a method below it by the compiler. Property is just a syntax sugar for methods:
public int IntProperty
{
Get
{
return 0;
}
}
public int IntMethod()
{
return 0;
}
Feel like the difference between Fields and Properties is kinda unnecesary, like basically a Field is a just a Property which value was just way simpler. But sure
I get it
A field is an actual data in the class. It can be mapped to a physical place in memory. Properties are not. They are methods that return something.
Thxs, but I am gonna keep mistaken then all the time, they just seem near synonyms to me XD
I will try not to though
properties are getter/setter methods in any other language
they are just c#'s sugar coated way to do things
well first thing, this object pool is likely gonna exist as its own all encompassing solution. Thats the purpose of it being made. Because of this, you're probably aiming to just have one of these, as a singleton. If not, well then now you're gonna have to inject the reference to the correct object pool in each and everything that uses it. Not always fun to do
2nd is you also have to handle resetting an object properly. This means like a pooled rigidbody (maybe a bullet) might need its velocity set to 0 when its released/gotten from the pool. Now that theres just a collection of object pools, all with objects that need to be reset in different ways, you have to figure out how you want to attach logic to reset an object.
In my case, i wanna also have some objects ignore collision from the character that spawned it so that a bullet doesnt hit the user it spawned from. This isnt really fun to setup. I know how to do it, but it doesnt feel right
They're totally not the same.
Field is simply:
accessor type name;
Properties need to have a getter setter or implement a lambda(=>)
So if I do like public float MyFloatMethod(){//Calculate something to return}; that's considered a Property?
No, that's a method. But you can implement it as a property.
public float MyFloatProperty
{
Get
{
Calculate something to return;
}
}
they are similar, but another takeaway is that you don't need to invoke properties like methods
but again, just c#'s special syntax of creating these types of getters
Ok, sure. It makes sense
auto properties though could be confusing though as they are both a getter/setter and a field
hence, property field
So if I have a Property and I call it and it is assigned to a method, it would just be like exactly the same that calling that method to begin with.
So, yeah, basically sorta of a getter
Why would you need it if you have a method that does the same thing? Properties are not for that.
Though, sometimes thy are used for that as well for readability
So, imagine you have an inventory class that contains a list of items. You don't want to expose the list to outside the class, but you want to know the amount of items in the inventory, so what you could do is implement a property that returns the list count:
public int ItemsCount => itemsList.Count;
That's a typical use case for properties. You can implement it with a method of course, but property makes it so much easier.
so now you use ObjectPool<T> instead?
ObjectPool is already generic, i just have a dictionary of them
I get that, but I also don't know why I would even want to hide something like that. But sure.
well typically you wouldn't want outside objects to have direct access to the list contained in your inventory, that would allow those other objects to modify the list potentially putting your inventory into an invalid state. so you'd expose the count through a property like that
When you use ObjectPool, do you still see the GOs in in the hierarchy?
Yes they exist in a scene, an ObjectPool is nothing special related to a gameobject. its just a collection of gameobjects and gives you whatever ones are available
Yeah, I could also make a public method that does exactly that if a really wanted that list to remain private; so I don't really get the use. Just another way of doing it I guess
the property is a method though. properties are just methods that look like variables to reduce the number of actual methods you are writing. you don't need special Get and Set methods because that's what properties are for
It really does confuse me that you don't need to invoke properties, especially on the caller side of things
which means that it's up to naming convention usually to clarify it for me
just don't have public fields, then you know that everything you are working with is a property 🤷♂️
To have good code obviously.
So whatever I have there is calculated at runtime when calling a Property?
yes public int ItemsCount => itemsList.Count; works *exactly the same as pubic int GetItemsCount() { return itemsList.Count; }
it's just easier and prettier to write
Ok, I kinda see where I can use it now
actually no it doesnt, because you have a lower case i
the name of the file and the class name doesnt match
yeah i just started coding so i jsut followed a tutorial for how to make the camera look around and i got stuck
you should make them be the same, ideally upper case, which then would require having a different name
keep ur filename and class names identical
looks that way
you probably have compile errors preventing unity from seeing that there is a MonoBehaviour in that file
exactly
yeah i noticed this error for a while and i dont know how to fix it
private PlayerInput.basicActions basic;
this line
if that is what the code looks like in vs code then you haven't saved it
its definitly saved
this screenshot says otherwise because that line of code is different here
and the error implies otherwise because it actually matches up with what that screenshot shows
im jsut messing with it but the error is ther efor both versions
did you copy the code from a tutorial?
pretty much
i mean i just followed the steps
pay better attention to the tutorial, your code is not exactly the same
and it's all because you've named your input actions PlayerInput and just allowed vs code to import the incorrect namespace
ok ill try again thanks for helping
The unfortunate catch with my code for my mercy invincibility is that I can push enemies around, even when I told it to ignore collisions. at least it doesn't stay invincible. https://hatebin.com/qhergypwtq
// Start is called before the first frame update
void Start()
{
rb = gameObject.GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
if(dir[1] == true)
{
rb.position -= -transform.right * conveyorSpeed * Time.deltaTime;
rb.MovePosition(rb.position + -transform.right * conveyorSpeed * Time.deltaTime);
}
if (dir[3] == true)
{
rb.position -= -transform.forward * conveyorSpeed * Time.deltaTime;
rb.MovePosition(rb.position + -transform.forward * conveyorSpeed * Time.deltaTime);
}
}``` Im using this script to immatate a moving conveyor and im attaching the script to multiple game objects and flicking certain bools in the array to true to get it to go in different directions however they all act as if the same bool is true for every instance of the script and I dont know why
try using else if
didnt work
thats not the issue
the issue is it thinks a bool is true when it isnt
what do you mean by flicking the bools in the array ?, show the code
That's physically impossible
instead of guessing, have you actually logged the values or use debugger
That sounds like YOU think it is false when it isn't
If the array that dir references has a true in its second slot, this object will move to the left (twice, by the way).
If the array that dir references has a true in its fourth slot, this object will move backwards (twice, by the way).
If an object is moving like that, then those booleans are set that way
I'm having 2 issues: only my pawns can move forward reliably, the knights, horses, king, bishop and rook are finnicky (they do work on occasion and not on others and I can't make heads or tails of what to debug)
the second issue is that after I implemented the gameManager script I am getting null errors out of the woozah
- BitBoard
- BoardCoord
- GameManager
- ChessPiece
- Piece Setup
I have to sleep but if anyone happens to see what I don't please ping me
Through further testing I've also found that the logic that prevents jumping pieces in the display moves section also doesn't work correctly
For the rooks and queens. The bishop works fine and so does the knight and the king
the parameter for duration?
yeh
so use that
its just showing the basic parameters
till the color
there are more signatures tho
welp, imma try it real quick
ohki its working now
thanks!
so its a float, so prob at most you can do float.MaxValue
how do i debug something after in the built game
like, when i shoot, i think my crosshair is not in the middle of the screen cuz the bullet's not hitting everytime
and i dont think there can be any other reason for them not hitting
yeah debugs dont work in build, you'd have to create some Line Renderers most likely
Debugging directly on the screen works
wdym on screen?
You may implement a small UI console and add the messages to it using tmp texts
na I think they were trying to see their Debug.DrawLine in build
Got it
or maybe i misunderstood what they wanted to debug lol
this is correct
i wanted to debug the raycast in built version
Hey guys, so about the new input system. How are control schemes meant to work?
To my understanding they were input modes that were defined by me but they seem to automatically change depending on the input detected.
So for example, I use the mouse/keyboard, I touch the joystick and it automatically switches to that
thats desired behaviour i believe.. unity automatically detects which device is being used and automtically switches..
you can tailor inputs for certain things.. 1 scheme for kb 1 scheme for joystick.. or a scheme that has both types of inputs for a singular action..
the old input system for example has two bindings for each Axis.. you could remove extra's if u wanted (by default i think both the old and new input system is enabled)
you could handle swapping manually to only use 1 type of input.. or remove any trace of a certain type of input from the controls
Okay, so from what I can see there is no option to disable the automatic control scheme switching. In my case, I want the control scheme to be defined by the options menu
Hello
hi, i need help making a character climb a wall, not wall jump but like climb up. my code rn has a lot of bugs and isnt working properly and im not sure what to do to fix it.
https://gdl.space/ebuzaxiqoc.cs
here is my code
you can manually chose which scheme to use using code
It wont switch automatically then?
you just have to create 2 schemes.. 1 for just the keyboard w/ no alternative keys like a joystick
Sorry to be persistant in asking, just don't want to write a system for Unity to just ignore it xD
Coroutines are trash if you use alot of methods?
Yep, have that
does it still respond to joystick inputs if u set it to only use hte new input system.. (in player settings active input handling is set to use both)
Is there any decent documentation on any of this you know of?
if ur schemes only include keyboard inputs i wouldnt think it'd respond to joystick inputs
theres lots of tutorials.. https://learn.unity.com/project/using-the-input-system-in-unity
Okay, so wait. Let's get this straight:
You have a map of keybindings called an "Input Action Asset".
Then inside each of those, you have Control Schemes which are defined in the Unity window.
So currently I have a single "default" Input Action Asset that contains two control schemes: keyboard&mouse and gamepad.
Did this by the way, it has helped yea
When the Gamepad is interacted with, it switches to that. Same for keyboard&mouse. That functionality is handy but in my context breaks my Input handling system, which I want it to be user defined in the options menu
https://www.youtube.com/watch?v=e30i55Hp-to&ab_channel=SasquatchBStudios
and also theres an argument to be made that you Want unity to actively be using both..
you said you wanted to chose in a menu.. but say I wanted to use a Joystick.. but it defaults to keyboard..
say i use a joystick b/c i dont have a keyboard.. how would i navigate thru the menu's to change it to use the joystick?
Yes. It is a good feature, actually I have made a project with what you describe there. But for this feature the game only should switch depending on an in-game setting
i can't find any specific tutorials on how to force it to use just keyboard but the new input system is supposed to be modular.. and allow u to use different schemes.. or no schemes.. etc.. #🖱️┃input-system would know how
Actually, to add to that, I can't find an tutorials OR documentation.
theres lots of documentation...
Yea, I think you're missing what I'm getting at, there is no methods/built-in functionality that implies you can use the Input system's control schemes manually. Instead to my understanding, the automatic behavior is not configurable...
Which further implies that it shouldn't be used like that, right? Confusing since it's a pretty concrete feature across many game engines
its an entire system.. not compareable to a single built-in method ud find in a Math class for example..
i dont think its fair to imply it couldn't and probably pretty straight forward to code yourself given a bit of research
doesn't imply it shouldnt be used like that.. as it is a full replacement for the old one.. what u can do with the old one u can do with the new one.. + more.. not less
seems around the web, ppl do use it like that
yea, its pretty lame.. I'm slowly using the new one more often than not
im stuck on unity 2018.2
and now that the newer versions of unity have both systems enabled default.. it helps me use it more often
ios 8 support 👍
Can I ask a question about learning Unity
I get your first point, yes. But for this project I do not want to take a well-defined system which has automatic behaviors I can't control out of the box and root it out using quick hacky solutions. That would create tons of problems later, especially when porting the project to newer versions when the Input system changes.
I'm still 99% sure there is an option for manual switching
Thanks though I appreciate your help. Like you say, guess it just needs more research on the forums and how others have done it
heres a thread that looks like it may have some promising info
I am watching a tutorial that is asking me to use Unity events. I understand code but I feel like learning this is useless because theres no way I could reproduce changing the editor. Do people usually modify the editor like this?
Thanks, I found the exact one too xDD was reading it when you pinged me
its useful skill to have to write editor scripts.. i've written a few to help me do tedious tasks or automate a process..
you wouldn't need to know how to write editor scripts, no.. but Unity Events is a different thing, and those would 100% worth knowing how to use
https://forum.unity.com/threads/how-can-i-set-a-specific-control-scheme-at-runtime.750461/
(Putting this here for anyone for finds this conversation later with a similar question)
The default event system works only with UI correct? I need to change the editor to use events on other things?
someone tag code sharing??
ohhh, you meant the unity eventsystem** its mainly for ui.. such as clicking, drag and dropping interactions.. but it can be used with 2D sprites as well.. and even 3d objects(anything with a collider) if its paired with a graphics raycaster
cant remember what sites
i thought you meant Unity Events..
my code is too long for dc too
http://www.hatebin.com is my fav
thx
but u can use !code to pull up an embed with a list of em
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
okay so my character is way too fast and I can only change drag to decrease the speed but then my gravity gets weird
float currentSpeed = isRunning ? runSpeed : walkSpeed; why not change the speed variables you already have
dont reallyunderstand what you mean
you ahve variables that control how fast you move.. runSpeed and walkSpeed are two of em..
why not lower those
yeah I know
instead of cranking up the drag
how to invert cinemachine camera direction?
when i pushed my mouse upwards the cam points down and looks at ground
float currentSpeed = isRunning ? runSpeed : walkSpeed;
Vector3 movement = (transform.forward * vertical + transform.right * horizontal) * currentSpeed;
rb.AddForce(movement, ForceMode.VelocityChange);```
it has to. to build `movement` you multiply ur inputs * the currentSpeed
if u drop that it will slow down..
Consider asking in #🎥┃cinemachine
but If I have 0 I cant move
and 0.3 does not do any
either
I gotta have0.000000001
or some is wrong
Player character rotation gets reset when moving
okay now it works I did some wrong first time
@rocky canyon went to do another job without figuring a fix, then noticed... 🙃 one of those days
Amazing how that isn't in the docs
is vs the blue logo orthe purple logo
VS is the purple one
I dont know if this is my coding or not but my character glides instead of walking so I continue to move after I´ve released "W"
!CODE
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
https://hatebin.com/ttvgbcvviz HERE Is my code
I know that it is drag but if I change drag my gravity lowers and It is not good at all
drag is basically air resistance
u want a Physics Material to apply to the rigidbody/collider its Friction
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
• Other/None
hey dumb question, if i uninstall vs code do i have to remake all my scripts
ok
aight cool
we got it configured
mind if we continue ith my issue?
ill reply to it for you
right ehre
Why is this thing visible in my game?
I thought this was supposed to be visible only in my scene
for me to see while editting the actual scene
look at this invisible green object at the end
Ive turned its renderer off so why is it visible?
this Green "END" shouldn't be visible in my game
is there any way to do this without removing its green symbol ?
I mean I can change this here
but i dont think this is supposed to be showing in the game play mode
should I turn off 3D icons?
(Just reposting so people don't have to scroll 400 messages up) But here I have these 2 scripts, which are causing these 2 errors that i have no clue how to get rid of. any ideas?
i can see how to fix the first issue
but idk how to invoke a method
at least i havent heard of it
oh eait
the errors have changed
there we go
ok nvm i fixed it
sorry if i spammed the channel
What is UIHandler?
is it a class you created?
ye
man
youre trying to put the class UIHandler into Gameobject
i appreciate it
but i fixed the issues
i wrote the script late last night
it was an obvious fix'
but i truly appreciate the help
I think the problem was the naming
UiLink and UiLink2 being 2 different classes is very confusing
but yeah)
yes
quick question yall, its a little urgent but if I rotated an object with:
transform.rotation *= some Quarternion like (0,1,0,0)
is there a way to make this my new (0,0,0,0)
or (0,0,0)
"Make it your new origin" as in like you'd get different results when asking for transform.forward?
wouldnt you be able to set it to something like a var?
idk i dont mess with quaternions a lot
err.. say after I rotated an object around the X-axis 90 degrees, when i rotate it around the desired y-axis
it now is rotating around the world z-axis
since i applied the 90degrees rotation on the object around the x axis, the object's y-axis is now alligned with the z axis (in our perspective)
the only way I can think to do that would be to apply the X axis rotation to a parent object and then apply a local rotation to the Y axis of the child.
i thought the easiest solution would be after I apply any rotation, I set the current rotation as my new default
there is no method to do that
so i can easily apply rotations again along the world's axis
ah
it would be like applying a rotation in Blender, current rotation becomes Quaternion.identity. Unity can't do that
Are you asking because a model is rotated by 90 on the x? This is a common issue with models. If done from blender you need to apply transforms before exporting it*
so the situation is that I wanted to mapped WASD to rotate an object around y axis when pressed A/D and x-axis when pressed W/S
when i rotated the object around the x-axis by 90 degrees and I want to rotate the object around the y-axis subsequently by pressed A/D
the object is now rotating around the z-axis
Maybe you want to use the relative to parameter here
If I have understood you correctly
how can i set a default value to a serialize field
Set a default value to the field itself, in the script
[SerializeField] float a = 5;
ah right i see perhaps i can rotate relative to the world space
i didnt know that that was a parameter, I appreciate it
Thanks
Np, always best to describe the use case. Otherwise it may be interpreted wrongly like how I and others did above
👍 fair enough, I will keep that in mind
Input.GetKeyDown returns a bool? if yes why
if(Input.GetKeyDown(KeyCode.LeftShift))
does not detect when i press shift
You'll have to show the entire script. Most likely it's in the wrong place
error CS0433: The type 'IAsyncEnumerable<T>' exists in both 'Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=' and 'netstandard, Version=2.1.0.0, Culture=neutral,
anyone know abt this error?
[SerializeField] int sprintMulitplyer=1;
void Update()
{
float xAxis = Input.GetAxisRaw("Horizontal");
float yAxis = Input.GetAxisRaw("Vertical");
if(Input.GetKeyDown(KeyCode.LeftShift)){
rb.velocity = new Vector2(xAxis,yAxis).normalized*Speed*sprintMulitplyer;
}else{rb.velocity = new Vector2(xAxis,yAxis).normalized *Speed;}
Debug.Log(rb.velocity.magnitude);
}
GetKeyDown is true once, when you press down shift. So you set the sprint velocity for exactly one frame.
use GetKey instead if you want the sprint speed for the entire time you press down shift
Thanks
finally uploaded my game prototype
thanks for the help.... i dont remember names so you know if u helped me
You're welcome
is it ok for player movement to use nested if? like use an if for sprinting and another for jumping and other things like that? and if no is it any other way?
Your question makes no sense. This depends heavily on what you're actually doing and there are a ton of ways you could go and implement something.
Often you should split your method into sub methods, which also improves documenting the code in a way. This could be one of those ways to omit nested if statements
Another one could be guard clauses, who knows
if(Input.GetKeyDown(KeyCode.Space)){
Debug.Log("Pressed");
rb.velocity = new Vector2(rb.velocity.x,jumpPower);
}
i did this in the update and when i press space it does register but does not matter how high i set the jump power it does not add any velocity
I'd say log rb.velocity after you set it and see what it actually becomes
Or log jumpPower
pro tip. Instead of just logging a string, log the variables you are using. That is useful information
If you still have this movement code it will override the jump velocity
i deleted from the code anything related to the vertical axis
i logged both of them and when i press space jump power says is 100 and Y velocity says its 100 asweek but the character is not moving
You'll have to show the full code again
Then consider logging rb.velocity in your Update method and see what that logs
This is the code for jumping in a different script
if(Input.GetKeyDown(KeyCode.Space)){
rb.velocity = new Vector2(rb.velocity.x,jumpPower);
Debug.Log(rb.velocity.y);
Debug.Log(jumpPower);
}
This is the movement code
void Update()
{
float xAxis = Input.GetAxisRaw("Horizontal");
//GetKey detects if the key is down for the whole period of time it is down
if(Input.GetKey(KeyCode.LeftShift)){
//Sprint when LeftShift is pressed
if(touchingLand==true){
Debug.Log("Sprinting While Touching Land");
}
rb.velocity = new Vector2(xAxis,0)*Speed*sprintMulitplyer;
}else{
//Move normally if GetKey does not get input
rb.velocity = new Vector2(xAxis,0)*Speed;
}
//Debug.Log(rb.velocity.magnitude);
}
hmmm for 1 frame it becomes 100 and right the next frame it becomes 0
so this is the problem
Yes, because you set it to 0
so both of those set velocity.y to zero
ahhhh
rb.velocity = new Vector2(xAxis,0)
waaait
This is why context matters
And make sure you don't immediatley try to pinpoint an issue in your question. Notice here the issue was a completely different part of your code 😎
can anyone check why my weapon swapping isn't working?
The functions do seem to work as my swap animation plays but weapon doesn't change when I scroll my mouse
https://paste.ofcode.org/8qfiY52Y46defHiExRyKPw
here's the mouse scroll input code
{ if (Input.mouseScrollDelta.y != 0)
{
scrollDirection = Input.mouseScrollDelta.y;
actions.SwitchState(actions.Swap); }
}```
The first thing to do would be log the value of weapon.Length
and put a log in WeaponPutAway to check that it's called
log value weapon.Length is 2
no logs came on WeaponPutAway
So it's not being called?
seems so
but then hows the Events being invoked