#💻┃code-beginner
1 messages · Page 587 of 1
Assets\Scripts\PlayerControls.cs(1179,19): error CS0102: The type 'PlayerControls' already contains a definition for 'PlayerActions'
So you also have a script called PlayerControls?
You're really gonna have to start coming up with new names lol
No wait
I have a script playerController,PlayerControls(made by input system) and PlayerLocomotionInput
Is Assets\Scripts\PlayerControls.cs the one that's generated by the input system?
Delete the one that's out of date
Assets\Scripts\PlayerLocomotionInput.cs(15,9): error CS0120: An object reference is required for the non-static field, method, or property 'PlayerControls.PlayerActions.Enable()'
Assets\Scripts\PlayerLocomotionInput.cs(16,18): error CS0572: 'PlayerActions': cannot reference a type through an expression; try 'PlayerControls.PlayerActions' instead
Assets\Scripts\PlayerLocomotionInput.cs(16,9): error CS0120: An object reference is required for the non-static field, method, or property 'PlayerControls.PlayerActions.SetCallbacks(PlayerControls.IPlayerActions)'
Assets\Scripts\PlayerLocomotionInput.cs(21,18): error CS0572: 'PlayerActions': cannot reference a type through an expression; try 'PlayerControls.PlayerActions' instead
Assets\Scripts\PlayerLocomotionInput.cs(21,9): error CS0120: An object reference is required for the non-static field, method, or property 'PlayerControls.PlayerActions.Disable()'
Assets\Scripts\PlayerLocomotionInput.cs(22,18): error CS0572: 'PlayerActions': cannot reference a type through an expression; try 'PlayerControls.PlayerActions' instead
Assets\Scripts\PlayerLocomotionInput.cs(22,9): error CS0120: An object reference is required for the non-static field, method, or property 'PlayerControls.PlayerActions.RemoveCallbacks(PlayerControls.IPlayerActions)'
We back at only 8 xD
I think you need :
PlayerControls controls = new() controls.Enable()
nvm just saw you did that in link
Do you have an action map named PlayerActions?
glad it's sorted 👍
Thank you!
Anyone know how to make the scroll wheel keybind more responsive, it takes a full revolution of my scroll wheel for it to register the keybind has happened
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Input-mouseScrollDelta.html this is how I detect scrolling, it's instantaneous with it
I haven't made use of scrolling with the new input system yet, but it should be the exact same equivalent in that
How are you reading scroll input?
https://paste.ofcode.org/JKEKFxSCCLpwL6xd5NYXgP hello so in my code I have added collisions and want so that upon every key press the walk animation iterates through its frames even when colliding so currently it works for the first 2 frames but then it doesn't switch to the 3rd and 4th frames upon colliding
Debug your code. Add logs or step through it with a debugger.
I debugged and found that this works only one time
if (keyPressTimer >= animationFrameRate)
{
Debug.Log("Player can't move, animation updating.");
keyPressTimer = 0f; // Reset the timer
currentFrame = (currentFrame + 1) % currentFrames.Length; // Iterate the frame
spriteRenderer.sprite = currentFrames[currentFrame]; // Set the new sprite
}
keyPressMode = false;
keyPressTimer = 0f;
}
Is there a way in general that i can avoid creating new functions for events to subscribe to
If possible I'd really like it if I could subscribe them all to a single ProcessButton
Hey anyone having issues where you assign buttons or objects in inspector but it still shows errors that they are not assigned? Idk wtf is going on
and then sort the functionality out by if statements rather than being drowned in function statements
individual methods, while more verbose in the code, are going to be better performance-wise because you won't need to go through a long chain of if/else to determine what code to run. and if they each do something entirely different then there is even less reason for it all to be inside of one master method
aye aye
I was hesitant to choose one or the other, but glad to hear that doing this sort of thing also works!
Thank you
Debug it further. If it doesn't execute, then the condition is false. Meaning the keyPressTimer is not iterated. So debug the code related to that.
Hey! So, I’m trying to figure out how to set things up in Unity. I want to make it so that when I click a button on an keyboard, a component gets turned on. And then, if that component is already there, I want it to turn off instead. How can I make that happen? Any tips?
If I uncheck the box, it remains visible. This happens in the actual game.
Create an instance of the component and call the .enabled method on it via code in your on click events and set the status there
If the component is turned on, then it is already there. By that logic, your second statement will always be true . . .
What others said + "remains visible" doesn't make any sense in this context.
☝️ This is also true. If you uncheck the box, you will be disabling the component. This will stop all Update methods from running; that's it . . .
Well, he's supposed to become invisible... And - he is visible 😦
What is "visible"? What is supposed to be visible/invisible?
And where?
Visible in the inspector?
One second please...
At least you're giving us more information. We didn't know anything about the object changing from visible to invisible. You are disabling a component called Trackable. Does this component enable and disable the object?
I'm talking about the blue marker.
Why should it be visible/invisible when you disable the script? Scripts don't render objects in the scene. Normally.
How are we supposed to know that? 🤔 You have to give details like this at the beginning . . .
Do you know how a compass works in games? Marking an object is its main job.
If you want that disabled, you don’t disable the component but rather the instance of that object via the code
In unity, you have components that are responsible for visuals of the object, like SpriteRenderer, MeshRenderer, ui Image, etc... So if you want them to stop rendering, you need to disable them, not your scripts.
Unless your script has extra logic responsible for rendering(or controlling the components related to rendering)
Basically, go and !learn the basics:
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
I'm saying that you didn't mention anything about the object being a compass or a specific object—for that matter. You just said, "Click a button on an[sic] keyboard, a component gets turned on. " That's all I'm saying . . .
If you want to prevent an object from rendering, you need to disable its renderer. If it's a UI object, you can disable the Image component or use a CanvasGroup component and manipulate the alpha property . . .
YES! This is idea! I'll try to change this
Disabling the object entirely also works but any code running on it won’t run so either do that or disable the renderers on it
Is it possible to add a instanced script to a gameobject? (Create a script, do some edits to it, then attach it to an object)
no, but why not just add the component then do the modifications to it immediately after calling AddComponent?
or you could just instantiate an entire gameobject (with the desired component on it) and set it as a child of that object
Cause I was wanting to pass a argument to the constructor of the script, which you can't do with addcomponent.
you can't do that anyway because invoking a MonoBehaviour's constructor does not create the MonoBehaviour on the native engine side so it won't correctly act like a component
MonoBehaviours do not have constructors; only C# classes . . .
They do have constructors, you just shouldn't use it yourself, and there's rarely a reason to declare one
Ah
true, i was tryna scare them away from it. they're called multiple times in the editor and during runtime. it's crazy . . .
isn't the Awake method similar to a constructor in unity's lifecycle?
sort of, yes. it can kind of be treated like a parameterless constructor. although you actually can define a parameterless ctor that will actually be called (though you would typically use Awake unless you had a legitimate reason to need to use the ctor)
makes sense, I never actually written a constructor and thought about it which got me wondering about it, thanks for explaining that
hello so my tilemap for solid objects has a composite collider with polygons but in some places polygons are not generated and my player doesn't collide with them pls help
Hi! What do Unity attributes like [SerializeField] mean? Can someone list the most common ones and explain them? Thx 😁
makes private fields be "serialized" and editable in the inspector
[SerializeField] means declaring some bool float or other things in your script if set to private they aren't editable in editor but can be changed in script and if public can be changed by both
Okay, thank you. Are there any other popular ones?
Thx
Worth mentioning that serialiation doesn't just mean it's editable, it also means the value is saved and will persist. Non serialized values will use the default values when loaded
you can edit it and that is saved in the scene or prefab or asset
id like my my mouse to stop when it hits colliders, so i need to make an "in game mouse", how do i do that?
https://hastebin.com/share/bixowekuda.csharp
https://hastebin.com/share/atacikebus.csharp
https://hastebin.com/share/urujepudaq.csharp
I need help... How to make the distance text false when focused=true for the object?
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
You could use a rigidbody and move it towards the world cursor position with velocity.
What I would do though, is to do a physics query (like SphereCast/CircleCast) from the previous cursor pos to the current one.
If the path is blocked, move the in-game cursor to the hit position. Otherwise move the in-game cursor to the actual world position.
why would u do it like that instead
The second approach would allow instant movement. First approach uses velocity so it might not be instant.
Depends what you want of course.
okay thank you
Somebody can help me please, 3 hours I fight with this
Hellloo, my enemy's projewctlie only goes on one direction, anyone know whats wrong?
heres the script
private void RangedAttack()
{
cooldownTimer = 0;
darkballs[FindFireball()].transform.position = darkpoint.position;
darkballs[FindFireball()].GetComponent<EnemyProj>().ActivateProjectile();
}
and this is ActivateProjectile
public void ActivateProjectile()
{
hit = false;
lifetime = 0;
gameObject.SetActive(true);
coll.enabled = true;
}
Are those the only scripts?
no, theyre just the ones that are responsible for activating the projectile
Then what is responsible for the movement of the projectile?
oh wait yeah, here
private void Update()
{
if (hit) return;
float movementSpeed = speed * Time.deltaTime;
transform.Translate(movementSpeed, 0, 0);
lifetime += Time.deltaTime;
if (lifetime > resetTime)
gameObject.SetActive(false);
}
forgot abt this one
transform.Translate() is a Vector3 method. The first parameter is the X direction, and since speed is likely a positive number, you'll travel in a positive direction on the X axes
So you'd have to have something check whether you're facing left or right
So if you're facing left, you just reverse the X value
Which you can simply do by adding - before movementSpeed
transform.Translate(-movementSpeed, 0, 0);
Like so
alright, ill try that, thanks
Assuming the Update() is the code for the projectile, of course
movementSpeed * (left ? -1f : 1f)
yeah that
yeah not that
Quick question, I can't find anything about this on the docs, but when I was messing with WaitForSeconds, vscode suggested WaitForSecondsUnit as well, which I can't find anywhere in the docs, and I tried looking it up and couldn't find anything. Does anyone know what that is used for?
That's not a built in thing
If it exists then it's from one of your scripts or packages
Weird that wasn't on my first google result page for WaitForSecondsUnit

That didn't show for me either, but cool, thank you
Checked 5 pages and still won't show up 🤔
have you tried adding quotes
Doesn't help
Ohh it auto corrects it to "waitforseconds unity" automatically 🤦♂️But doesn't change the text field
if you aren't using visual scripting and you work alone/no one else is using it, i'd recommend just uninstalling it so you don't get those irrelevant suggestions
I'll double check if anything references it in any way, and remove it if not, thanks
could try searching for the visual scripting namespace throughout your codebase
you most likely won't be using it without knowing about it
Alright, also probably a really dumb question, does a while loop finish the current loop if the variable its running against is changed? ie
bool run = true;
int x = 0;
while(run) {
p("1");
p("2");
if(x == 10) run = false;
p("3");
p("4");
x++;
}
public void p(string s) {
Debug.Log(s);
}
Or does it cut immediately?
i mean. you have all that written out, 
can you help me please with this, guys? 😦
you can try in like c# online stuff
... I didn't want to try it in my project, as it's semi broken... And forgot that online compilers were a thing XD oops
but the current loop runs until completion. while doesn't know what variable it has, it just has a condition that it checks at the end and goes back to the start
Thanks
while is just shorthand for if goto
all control flow statements can be decomposed to if+goto, frankly
so if you understand that, you can figure out how any control flow statement works
(disclaimer: you should not use goto.)
hello so my tilemap for solid objects has a composite collider with polygons but in some places polygons are not generated and my player doesn't collide with them pls help
that's a lot of code for a very short prompt. can you be more specific as to what parts are relevant here?
I think protected override void HighlightLogic in ImageIcon.cs
Focused in Trackable.cs
And... public override void UpdateDistance in ImageIcon.cs
you didn't show ImageIcon
wow im blind sorry one sec
Does anyone know a online c# compiler that supports unityengine code?
that would just be unity online
you could copy the relevant types/methods in directly
or write dummy placeholders with appropriate signatures
what do you mean by "make the distance text false" here?
Oops... I mean TextMeshProUGUI distanceText=false
TextMeshProUGUI is not bool
you can't do that
that doesn't even make sense, what are you trying to achieve by doing that?
What should I do then?
i have no idea what you're trying to do
is it possible to make a textmeshprogui bool function?
Are you asking for enabling/disabling it? Setting a boolean value makes no sense here
sounds like you're stuck in an https://xyproblem.info here
Components always have an enabled field if that's what you want
just hide this TMP text
So enabled field
when the protected override void HighlightLogic is in effect
Behaviours, not Components
Or SetActive is also something you might want to check
I want to make it so that when HighlightLogic logic is running, then distancetext becomes invisible.
I tried... No working...
What code did you use here?
Maybe you can help me with this?
When I'm using SetActive false is distancetext?
show the actual code you used
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
I'm trying to make a timer for a incremental game that will update the timer when the time is upgraded on it's own, will this work?
(Sorry for all the code questions, the class is still a complete mess as I'm not done creating everything needed inside ^^;)
public int x;
public float time;
public void Init(string[] args) {
x = 0;
time = 1;
StartCoroutine(Tick(time, true));
}
public IEnumerator Tick(float time, bool run) {
while(run) {
yield return new WaitForSeconds(time);
Console.WriteLine("Waiting: " + time);
if(x == 10) UpdateTick(run);
x = x + 1;
}
}
public void UpdateTick(bool run) {
run = false;
time = 0.5;
StartCoroutine(Tick(time, true));
}
Can you try logging what visible and/or state gives as a value here?
They should be false
This way you can verify the code is reached and valid
https://unity.huh.how/debugging/logging/how-to
where's UpdateDistance called
About this?
Put a log message in them and see what the boolean's value is
I don't see why this would not work. Did you try it?
There are better ways, but a coroutine generally gets the job done
run is local to Tick/UpdateTick. the assignment in UpdateTick does not affect the while in Tick.
you have an infinite loop.
Crap. Thank you, and Fuse, how would you do it then?
And the class is full of errors as I'm implementing too many things at once, so can't test it without removing a lot of half finished things ^^; Sorry
do you need to do something each time interval? if not, why not just wait 10 * time
If this is supposed to be a timer that runs a certain amount of time, you could just keep a "target timestamp" variable and have an Update method check Time.time until it passed that timestamp. When that happened, call UpdateTick or whatever would invoke the behaviour after a timer and update the timestamp
The documentaiton of Time.time has a very good example
also x seems very weird there. it's never reset back to less than 10
so the if will only ever run once
i'd probably just opt for a for there instead of a while
oh also Console.WriteLine wouldn't work in unity.
What should I do?
public IEnumerator Tick(float time, int cycles) {
for (int i = 0; i < cycles; i++) {
Debug.Log($"Waiting: {time} ({i})");
yield return new WaitForSeconds(time);
// do per-tick thing
}
UpdateTick();
}
honestly UpdateTick might not even be necessary, you could just handle it all in a single loop
It's cause it was edited to work without context from the class.
Basically it's the game loop. This timer updates any changed strings, checks if things can be unlocked, does passive energy generation, handles updating the cost of the item when its bought.
wrong person lmao
Ugh, this is why threads exist
public class Example : MonoBehaviour
{
private float _nextTick = 0.0f;
private float _interval = 5.0f;
void Awake()
{
_nextTick = Time.time + _interval;
}
void Update()
{
if (Time.time > _nextTick)
{
_nextTick = Time.time + _interval;
// Put your logic here
}
}
}
Here's a basic example of how you can use Time.time here
@sleek flare
Preferably you would split this from the monobehaviour
a lot of stuff doesn't make sense without context. if you remove stuff, at least leave some comments so we know it's doing something lmao
The convenient thing about this is also that you're not hard tied to an interval. If for some reason you want some sort of cooldown, you could just decrement the value of _nextTick instead of extra steps to get it working
And also, if you had to tie a visual indication of the time left, you can just get the difference _nextTick - Time.time and use the result in some progress bar for example
And lastly, if it matters to you, this is very multiplayer friendly since you just need to inform users of the next timestamp in most cases
It's unfinished, but heres the entire class. There are some references outside the class, but mostly its just actual objects assignments to variables.
https://pastebin.com/dHawze5S
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
See the message I posted below them. I also linked a site explaining how to log values. You need to make sure the method is reached at all, and the boolean you pass truly set it to false
I will warn you I'm not too good, but I can generally bullshit my way through things ^^;
The timer basically just manages how often the different strings showing you information are updated, and how often you gain energy (by delay)
Round(((5*(tier+1))*((tier+1)*1.2)))
this could definitely be simplified
it's equivalent to (tier+1)*(tier+1)*6
or Mathf.Pow(tier+1, 2)*6
Yeah, it probably can be ^^; I was trying to make it exponentally grow, without it getting out of control ^^; This is what it was outputting in a older project
I'll try using the ones you suggest
Yeah
btw, exponential and quadratic are different
what you have there is quadratic
you might want to try something like Math.Pow(1.5, tier), for example (for exponential)
That's what I meant.. I think? I think I didn't do that one cause it grew out of control too quickly
Fair!
yeah exponential goes quite fast
exponential is a^x for some real a>1
quadratic is x^2
(of course with constants and lesser terms as desired)
hello so my tilemap for solid objects has a composite collider with polygons but in some places polygons are not generated and my player doesn't collide with them pls help
Is there a way to like make that the logs just show the the last print for a source?
In like, not collapse all that are the same, cause they are showing updated data, I just wanna see just the most recent one
public static void ClearLogConsole()
{
#if UNITY_EDITOR
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetAssembly(typeof(UnityEditor.SceneView));
System.Type type = assembly.GetType("UnityEditor.LogEntries");
System.Reflection.MethodInfo method = type.GetMethod("Clear",System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
method.Invoke(null,null);
#endif
}```
```cs
ClearLogConsole();
Debug.Log("NewInformation);```
I'm not aware of a way to remove just some items from the log
You may want to use OnGUI to display a value in the game view instead
yea, me neither.. i wasnt even sure u could clear the console at all..
If you want to display a variety of things, you can do something like this
but someone figured it out.. and i had to try it for myself. but reflection..
https://discussions.unity.com/t/clear-console-through-code-in-development-build/87213/6
lol..
- but now its this
- oh they changed it to this
- in the newest versions this..
- etc
public class DebugDisplay {
public event System.Action DrawDebug;
void OnGUI() {
GUILayout.BeginVertical();
DrawDebug?.Invoke();
GUILayout.EndVertical();
}
}
Subscribe to DrawDebug and run more GUILayout methods in the subscribed methods
e.g. GUILayout.Label("Here is my value: " + value);
now imma remove it b/c i dont like code messing with the unity editor assembs
Well, it would be amazingly usefull for a log like this
that'd still show a nice countdown in the very lower left corner
I created an IDebug interface that requires an IEnumerable<IDebug> method
the debug manager draws a checkbox every time you yield an IDebug and keeps track of which ones are enabled
$"> {this.gameobject} is trying to attack from {Vector3.Distance..}; needs {stats.attackRange}"
why aren't u using string interpolation btw?
this is neat.. i bet ur project is chockd full of nice utilities
i always see u mention them here and there
I plan on making another custom attrib today..
[DebugValue] private float ValueToWatch;
it'd make it read-only w/ a highlight in the inspector 🙂 🤞
another useful bit:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
namespace Pursuit.Singletons.Prefabs
{
public class DebugDrawer : SingletonPrefab<DebugDrawer>
{
private readonly List<Action> actionList = new();
private int lastFrame = -1;
private void OnDrawGizmos()
{
foreach (Action action in actionList) action.Invoke();
}
[Conditional("UNITY_EDITOR")]
public void RequestAction(Action action)
{
if (Time.frameCount != lastFrame)
{
actionList.Clear();
lastFrame = Time.frameCount;
}
actionList.Add(action);
}
}
}
or maybe a little icon next to it.. havent thought it all the way thru yet
I used this while debugging a very nasty sub-frame problem
I was using something before it got updated, so I was off by a frame
I needed to be able to view the position of something at several points during the frame
so I couldn't just display it in OnDrawGizmos
is this basically a in scene Toast type thing?
Well, I am getting this, and it's not as usefull as it could
i've already shown u how u could clear the console b4 each log
nah, it just delays drawing normal gizmos
and fen gave alternatives too
thats been on my to-do list for so long
positioning is my main issue..
i can do it.. but it takes so much trial and error lol
vertical layout group
oh, i have an in-game one that uses a layout group..
but im talkin more of just a simple Debug type toast system. that would popup from the bottom..
stay a bit and then disappear
tick "use child scale" to let them transition in and out too
i'll see what i can't manage, i do feel like today should be an editor day 🙂
hello so basically in my tilemap some tiles do not have polygons in composite collider 2d pls help someone
you can manually add to or edit those colliders right?
you can specify/edit the offsets manually too but it doesn't work they aren't generated
ah, ok.. thats what i wasn't sure of..
can u show us a screenshot?
what is it ur generating? side/scroller?
ye sure
see that here I can walk through some tiles ignore that machine but can you see the player going through the boundaries cause no polygons were generated
thats odd..
yeah
im curious.. can u quickly put the player beneath those bottom colliders and see if u can walk thru them the other direction?
what?
yup as they all are part of same tilemap
makes me wonder if the colliders on the bottom are inside out
if that makes sense..
no see in that video the player can move both ways through them
this one
Any idea why my char isgrounded when on default unity plane with the whatisground layer but when on a cube created using probuilder isgrounded always returns false?
does the probuilder cube have the same layer as the plane?
yup
my first two guesses would be..
- make sure the probuilder cube has a collider
- check the scales of the cube make sure its not weird. or inverted or something
then some follow ups would be.. does this issue happen with other probuilder shapes?
are there any errors in the console or anything that may be breaking the logic?
i use raycasts for my ground-check and it seems to be working fine with probuilder.. let me test again to make sur
this is the cube
the console has no errors, let me try creating another probuilder shape real quick
ya, probuilder cube seems to be detected by raycasts just fine
im way outside my wheel-house w/ inputs but could u just use two different canvas objects?
created another cube, same results but then i tried creating a custom shape and it worked as intended
are u stretching the cube down into a plane?
might have something to do with the scaling, as i previously thought.. but then again im just spitballing
if it works for a plane, and works for some other shape, i think we can assume its not the logic..
i do stretch it but not enough to be a plane i would say
what happens if u toggle "Convex" on the collider?
same results
i made them both to be the child of the player input manager
https://paste.ofcode.org/EA4cdndipEqGgay5D7ytQS
hmmm 🤔 i'd have to think/research a bit myself. im clueless as of now sorr
hey, i just had an idea.. since its just a cube.. use a "BoxCollider" on it
instead of its default MeshCollider
ps. || learn blender, you won't regret it ||
same results :/ that being said theres something i forgot to mention, if i move around im able to jump because for some reason in a few frames the isGrounded variable is set to true and quickly becomes false again so with good enough timing i can do a jump, if i stay still then it just remains false forever. Also heres the script in case it can help solve the issue https://paste.ofcode.org/GYj2M8KGkwnh99NPjg8vpp
i just dont understand how it being a cube changes the outcome of the ray
i think u should use more of a margin here
i use .2f
.01 sounds ridiculously small imo.. its probably just getting inconsistencies
alright, let me try
same outcome, the reason why i changed it to begin with was to prevent a second jump before the capsule touched the ground
ya, but i dont think .01 would be enough..
especially if ur using something like a CharacterController..
like here, when u start the game.. it sorta hovers a bit.. gotta compensate for that.. either w/ a longer raycast or a smaller Skin thickness
that being said.. if ur having issues w/ the raycast i would either
- use gizmo's to visualize ur raycast so ur not just doing guesswork.. or
- use alternatives such as SphereCast, Overlapsphere, CheckSphere, etc
theres soo many different ways to do ground checks i couldn't even think of em all
yea ill try the gizmos, was looking for a way to visualize it but couldnt quite get there until i saw your code snippet
a raycast is probably the least Accurate imo
what would you recommend instead
b/c theres times when u'd need to compensate. like on a slope for example.. u'd need to cast farther than u would if u were standing flat
i like to use raycasts.. but i use an Array of them.. making a circle around the bottom of the player
i see lots of ppl using OverlapSphere tho
is this a CC or a RB?
im afraid im not cool enough to know what those stand for 😔
rigidbody or character controller
rigidbody
the reason i asked is because a character controller comes w/ a built-in groundcheck already
oh, interesting
Rigibodies are more powerful but harder to work w/
a kinematic rigidbody imo is the best of the best
i used this one while i was learning.. that way i could focus on other things..
just mentioning.. not suggesting u use a third-party one if u really wanna build ur own..
but a Controller is a very important step.. and they take time to get right
https://www.youtube.com/watch?v=jxCVHBMdTWo&t=36s heres a decent video that kinda goes over different methods
then u can figure out which one u want.. and search up better sources
thanks for letting me know, ill check it out and then decide from there
good luck mate.. come back if u still struggling afterwards
https://medium.com/ironequal/unity-character-controller-vs-rigidbody-a1e243591483
one last resource.. heres a guide that tells u what each mean Rigidbody or CharacterController.. they both come with pro's and cons
awesome, thanks 👍
CC is pretty bad ;)
kinematic rigidbody if you want custom physics without being bound to a single collider type
The selling point on that site is that it does decent climb detection for stairs, but the sloping is half-arsed
I just hate the capsule collider as a character body because it will slowly creep off ledges
lol.. funny u say that.. that was the most challenging thing I did..
i now have logic that kinda shoves u off the side when u get too close to it
LedgeSlip.cs
lol yeah im bias on that. I mean it's done for you with CC but if you wanted a bit more control just do rigidbody kinematic
CC is meant to provide some template to use for custom physics, but even the template itself isn't always the behaviour you want
facts.. I use this one..
purchased it before the KCC was as popular as it is now
i dont even remember seeing the KCC until way after
it really should have a set of behaviours for things like slopes and stuff like moving platforms if it wants any sort of identity
i dont understand why they havent done something like this for the CC yet
slopes
a better groundcheck
and moving platforms would make it much more approachable
Probably just expect people to use KCC, but I feel like they should change all the Unity templates over to using it instead
Explaining KCC is not as easy. And the example controller is just that, an example.
ya, i always try to explain "if u just want a controller to focus on other things" when i suggest it
its definitely not for the faint of heart.. pretty involved when u peep at the code 😄
The CC examples I feel are just as verbose as KCC
but there isn't really a general abstracted version of KCC so you may need to decouple some of the logic
hi im trying to drag a sprite in and it keeps trying to save a new animation for some reason
what am i doing wrong
Anyone knows how to make a character jump? in 2d i made this code but it doesnt work
public Rigidbody2D rbd;
public float force;
void Start()
{
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape)) {
rbd.AddForce(Vector2.up * force, ForceMode2D.Impulse);
}
}
}
didyou put script on gameobject ?
also !code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 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.
might wanna use another key to test ur jump..
everytime u try to jump ur gonna unfocus the game-window
yess
o ya why tf is it Escape lol
ok ill tryy
oh waitt
im stupid
thougth it was space
HAHAHA
thanks guys
u tripppin me out lmao
how do i drag and drop a sprite without it trying to make a new animation
u click the little arrow to open up the sprite sheet..
select (1) of those and drag it in
or just create empty gameobject -> add a sprite renderer and add the sprite to that
is this only in new version cus why can the guy im following just drag and drop the whole thing in
if its a single sprite.. u can do it that way
if its a sprite sheet w/ multiple sprites.. it assumes ur trying to make an animation w/ all of them
when u select something check the inspector..
one says "Sprite" one says "Texture2D"
ye
whats a good way to come up with a game ideas as a beginner?
try to mash 2 already existing games/mechanic together , stuff like that maybe
just start building stuff.. find the fun... then iterate on that
eg , what happens if you add guns to a game like flappy bird , besides pipes maybe add turrets and stuff you can shoot around
that reminds me of a game dougdoug made where he adds a gun to snake. you all probably dont know who im talking about... anyways some how my brain now wants to make a zombie type shooter game.
oh yeah that sounds good too. zombie games are always fun (to me at least)
i could add levels and other stuff i suppose.
can i get help ?
maybe?
I'm still new to new InputSystem, not even sure what to look for lol
my virtual cursors were always virtualCursor.position = mouseWorldPos
im tying to do double cursor for 2 controlers
so they could pick 2 bottons in the same time
where is the instantiating part
idk how are the cursors spawning ?
no idea sorry, I don't know enough about InputSystem yet to know how virtual cursors work
tnx anyway
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
@naive pawn
how do i move a canvas?, my rect transform have everything blocked
You don't
right, so start debugging
check if shootingDirection is consistent, if not, check if the ray in CalculateDirectionAndSpread is correct
@rocky canyon i checked out more about the different ways to implement movement in unity and ended up choosing a dynamic rigidbody, i ended up fixing the previous bug and now the groundchecks are flawless, thanks for the guidance 👍
np.. good luck on ur journey 🙂
You click on the left hand side of the numbers in VS, and it adds a red circle
this makes it into a break point
This means when you press play, and Unity hits that line of code, it will stop the game and it should show yout he state of said code
During that time, you can also right click your variable and add it to a "Watchlist" - and when you do add it to a watchlist, you'll see it in your Watchlist directory
what you're looking for here is to see if your enum, ShootingMode is always the sameShootingMode
Now - if you don't feel like doing all that, you can also put in a Debug.Log($"My Enum mode is {ShootingMode}");
Haha shouldn't have said that
That is a basic C# programming 101 know-how
Yeah I'm starting to think Sani is a troll.
i have never done debugging
Knowing where you write a line of C# code in an existing script is not part of Debugging
thats where u write code
C# has a structure to it. Do you know it?
i never needed it
you don't write statements outside of classes in c#
I'm sure you didn't since you are used to Roblox. but Unity is not Roblox. You DO need to know C# if you intend to use Unity
well - intend to use it without trouble anyway
i told u i never needed it
in unity
you need it now
How many games have you made with Unity??
Why you guys be so hostile, teach him
1 and this
buddy you gotta stop being overconfident
💀
We're trying. But he's saying he doesn't need to learn Unity Learn or anything because he knows Unity VERY well. But then he doesn't actually know it and it's making it hard.
He basically needs to 100% hand holding
your stubbornness to learn is gonna get you nowhere
yep
alright well - anybody working with Unity in the long run will require C#. There's no way around it. Unless you hire a programmer of course.
But if you intend to do it yourself, you're going to need to learn it. That's where UnityLearn will come in
i know that it needs c#
i learn c#
Yes. And you need to learn C# and how to use it
Okay go learn it
by the time i do that u will leave
heh. Well you don't learn C# in a single day. And also - that's just how Discord works.
That's why I am strongly encouraging you to go to Unity Learn. It's always there. So no matter who is on the server or not, you'll have a resource.
i dont need unity learn
So your plan is to just have us answer every question and fix every problem for you?
i am new to making 3d games, and i cant get my movent system working, can someone help?
i encounter those rarely
buddy, we're not gonna cater to every tiny question when you lack basic knowledge
you misidentified gameobjects just earlier
go do fundamentals
if not to learn, to at least communciate effectively
wym
you said you had multiple "same" gameobjects when you clearly did not
copied
cloned is same
they are not the same game object
they are instantiated from the same one, but they aren't themselves, the same gameobject
that's simply just a misunderstanding you have
yeah sani look - at this point I can't help you because you don't want to actualyl listen to our advice.
I will help you when you go through the lessons on Unity Learn. OR - I will help you if you pay me money to tutor you one on one (which I doubt you want to pay).
So at this point I'll wish you good luck, since you're too stubborn to actually learn
they have exact same mesh and stuff it didnt make any sense to me use layered collision at that situation
when i did it it didnt work
I don't mean to belittle you, I'm trying to make you realize something here.
You've consistently showed a lack of understanding of some fundamentals.
Your lack of knowledge of those fundamentals causes problems in you communicating issues to us, and us communciating solutions to you.
You simply don't know as much as you think you know. You're way too overconfident.
can someone pls help with my movement system, i am very new with 3d games
i understood what those were
clearly not, when you refused to use them
You've denied various very useful resources. If you're not willing to accept our help, we can't help you.
that's all.
when
!ask
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #854851968446365696
we can't help you if we don't know what your specific problem is
hes not gonna find anything on google search and understand it
also how do i fix my problem
i dont have time now, gtg, but can reach out to you when i know?
just ask here
ok
feel free.. meet us half way and we're all willin to help
you have not debugged the values i told you to debug
where do i write that code
Debug.Log($"My Enum mode is {ShootingMode}");
- where it's used
- that's not the value i told you to debug
u never told me what to debug
only him
and how do i check that
log them right after you calculate them
in command window?
how do i do it
was i supposed to put it in command window
No it has nothing to do with command
then where?
You have to go back and learn the basics of C# before you can continue your endeavor
in your code. Debug.Log is a function
i dont think that it even mentions debugging
because debugging is a skill, a programming concept, not a c# concept
then how am i supposed to know it
well - I'm telling you to write a single line of code, and you don't know where any lines of code should go becuase you don't know the C# structure to a class
You go to Unity Learn
where do you put code
if you understood c# structure, you should be able to answer that
let me be more specific; where do you put statements
this unity learn is specific to the C# side
Folks, does anyone have any idea why sometimes a game object isn't properly destroyed via Destroy(gameObject)
can u not answer normally
someties it's because I was referencing the wrong gameobject to destroy
inside methods, properties, lambdas, constructors, and static blocks
now which one of those do you have in your code
It seems really random. I was calling the function to do this within an animation clip originally so I thought that was just unreliable
I will note give you the exact answer, because there's too much you don't know. If you want me to literally do the code for you, you'd have to pay me.
otherwise, go through the tutorials here. These are specific to C# (not all of Unity) https://learn.unity.com/pathway/junior-programmer
you gotta be more specific than that
if you called it correctly on the right object from the main thread it should Just Work™️ as it's supposed to
couldnt u say that from start
This function lives on the GameObject that's to be destroyed itself
are you running into the delay? from the docs:
The object obj is destroyed immediately after the current Update loop, or t seconds from now if a time is specified. If obj is a Component, this method removes the component from the GameObject and destroys it. If obj is a GameObject, it destroys the GameObject, all its components and all transform children of the GameObject. Actual object destruction is always delayed until after the current Update loop, but is always done before rendering.
your object will still exist immeidately after calling Destroy() until the end of the frame
Interesting
you might require a this.gameObject to help point it to the proper object in question. You also have to make sure you're not destroyign the component
you can use DestroyImmediate if you need to do it immediately
I mean it already works 95% of the time
but what do i write to debug it
I'll have some food and then revisit the code to test some fixes
if you knew c# you wouldve known already 
If A checks B every frame and B destroys itself at some point, the results will depend on execution order
if A does the check after B calls Destroy on itself, then it'll see B as still existing
i thought u were asking different thing
B checks on B in its FixedUpdate
(even though B already called Destroy on itself)
Ah, fixed updates do not line up with frames
Unity runs the FixedUpdate messages zero or more times at the start of the frame, before Update
Changing it to just Update was the first thing I was gonna try
But I still don't understand how it's causing the object to be around forever
what do i write to debug
There are 3 debug genders:
Debug.Log("this is some text. hi!"); Debug.LogWarning("this message has the warning icon"); Debug.LogError("something broke in your game. here is a red error.");
i dont even know what im debugging
what are u building?
and what do i write that in
I see
it shoots backwards when i go backwards
to debug some variable a, you log the value of that variable around where the use site is
there's many things that could cause that.
ive told you what variables to debug
prefer interpolated strings over concatenation
.tostring?
$"text {variable} more text {other variable}" etc
.ToString is called stringification
Oh ok, sorry I'm not familiar with it
can someone help me with something?
ask your question
Debug.Log("The value is" + shooting direction);?
How would I get the variable isPressed from a script in gameobject ButtonU from a script inside the player?
New Unity Input system?
wym
variables with spaces arent accepted. check your variable in your script and then you'll be ready to go 🙂
there are two unity input sytsems - We'd have to know which one you're using. If you're using 2.0 you probably had to go through some package hijinx and a restart of Unty
i dont think im using the new one
prob the old one
@echo kite I can't rly see what part of the weapon is causing the shoot direction problem
i dont think i have shootingDirection in variables tho
thats why im asking
Okay so what I think you're doing - you hover over a button. Press down - adn you want to confirm if the mouse button was indeed pressed? or youw ant to confirm WHICH UI button you pressed
i thought bullet hit another one and it ricocheted but i couldnt fix it using collision groups
sorry, ask someone else because I don't know how to fix. I've seen the script
what if you comment out the recoil parts of your script?
`IEnumerator ShootGun()
{
//DetermineRecoil();
StartCoroutine(MuzzleFlash());
yield return new WaitForSeconds(fireRate);
_canShoot = true;
}`
Just to see what happens
why its black
https://prnt.sc/Yr3VOJPOhRdH
isn't white full alpha
can you click that color inspector
the button already works and it has a variaable named isPressed that says if it is pressed or not, but i do not know how to reference that variable in my player script (to make it move with the buttons as well as wasd)
okay silly question - why does your Player script need to know if the button was pressed?
@ashen frigate not a code question, let's continue in #💻┃unity-talk (just realized now, sorry.)
ohh sry
so that it can move the player properly
ahh so it's a UI that you click, and if it clicks, it tells the player to move up or down or left?
that is what i was hoping, i already ahve the player script written that works with wasd, so i was hoping i could just access the bool from the ui button
there's a coupel ways to do this, but simplest is this
In the UI inspector, add your player to the OnClick slot. Then tell it to fire a "move up" function in the funtion drop-down
thanks ill try that
also - as you learn to code, you're going to learn about singleton's. It's not bad to have a GameManager as a singleton in the future, though many might disagree.
If you don't know what I'm talking about, no problem. You'll get there soion
how would i find the function in the dropdown?
you drag the script on it or select the script class name
i think i found it
so that dropdown only works with functions that are public. Make sure your function to move forward is public
yep
It seems to be a Unity API error, right?
It refers to this code
public static T[] LoadAll(string label)
{
T[] res = null;
Addressables.LoadAssetsAsync<T>(label, null).Completed += handle =>
{
if (handle.Status == AsyncOperationStatus.Succeeded) res = handle.Result.ToArray();
Debug.LogError($"Could not load '{typeof(T)}'. Do the references exist?");
};
return res;
}
I tried to make the function work, but wasd applies the moveInput variable, and my button doesn't. How can I make my button function work with the moveInput variable?
what's the script you're using to make wasd work? Paste it into a code paste bin
oops dyno
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
that is the update function that moves it
Ahh right now it's programmed to only work with your keyboard. if (Input.GetKeyDown(KeyCode.Space))
yeah, but right now i just want to start with making the up button work
public void MoveUp()
{
playerAnim.Play("playerWalkD");
direction = 0;
}
this function works but it doesnt move the player (i need to set the moveinput)
But the moveinput probably gets overridden by your inputs?
so no matter what you do with your button, update will override it
Moveinput is created by my inputs
and modified by my inputs
i was thinking if i could set moveinput with the button
I'm trying to think about the best way to do it, but you really only gave me part of the script. Is this the entire player script?
no but that is the movement part of it
Let me see all of it
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
if you want to detach it from inputs but move it by buttons, you can just create a method that sets movement vectors and then decrease them on update or whatever you want your game to behave like
Okay a couple thing.s Do put not these in your Update
rb2d.constraints = RigidbodyConstraints2D.None;
rb2d.constraints = RigidbodyConstraints2D.FreezeRotation;
You should put these in your Start method. Fidn them once and done. Right now you have them repeatedly looking for the same things over and over again when it should be a once and done
Same thing for your moveInput, etc
find them once and be done
Alright, I put those in my start method
and in your Move() you probably want to set your moveInput.y to 1, and that SHOULD drive it upwards.
however, that will only ever move it up
it seems that the function only happens when the button is released, but it needs to happen repeatedly while the button is pressed
okay well , you can maken five public void functions, one for each movement, and then one for StopMoving. In those functions, you'll assign your move inputs accordingly. moveInput.y =1, or -1. etc.
I also realized I might ahve guided you wrong (my pardons). You do want to get your GetAxisRaw fucntions in Update, because we want to check every frame from movement. So you'll put this back in Update()
Vector2.zero;
// Check keyboard input
if (Input.GetAxisRaw("Horizontal") != 0)
{
moveInput.x = Input.GetAxisRaw("Horizontal");
}
if (Input.GetAxisRaw("Vertical") != 0)
{
moveInput.y = Input.GetAxisRaw("Vertical");
Again, sorry about that...
Recommend you use moveInput.Normalize() to keep the movement normalized
Here's a reworking. I was pretty quick about it, so as you look through it pay attention. https://pastebin.com/j7pDUu0M See if this makes sense and helps
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
With that script, the button doesn't work. I have the button working, but I don't stop moving in that direction. Additionally, it only happens after I release holding the button instead of when it is pressed down.
I see. I'll have to think about it 🤔
Is there a way i can find out what direction/point im looking at? like when im shoothing that i shoot in the derction the player is looking
is this 2d or 3d
3d
presumably the direction the player is looking at is the camera's forward direction so you can just use that
yea thanks and woud that be the point im looking at or just a direction lik z x
Okay you can try something like this script: https://hastebin.skyra.pw/iwijiruder.csharp
In this case, you will add it to your UI button. You will tell it what direction that button is supposed to correspond too - whehter it's left, right down, etc. When the button is pressed, it will use the enum int to tell your player the direction is 0, or 2, or whatever.
cuz what if my camera is looking bettwen x & z?
that would be the direction it is looking
ill try it thanks
You will update your player script to have a public function with an input parameter of int. And in theory this SHOULD send a signal from yoru btuton to your player to move left or right, etc
Alr, ty for the help.
Hope it works!
can someone explain me why I can't move with this code in a 2D object?
public class PlayerMovement2D : MonoBehaviour
{
public Rigidbody2D Movement_For_Game;
public float moveSpeed = 6f;
private Vector2 movement;
void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
}
void FixedUpdate()
{
Vector2 velocity = new Vector2(movement.x * moveSpeed, Movement_For_Game.velocity.y); // Somente altera o eixo X
Movement_For_Game.velocity = velocity;
}
}```
any errors in the console?
nop
is the component actually attached to an object in the scene
actually when I used debug.log it said that it moved but in the screen it was the same
show the rigidbody
this?
Guess who finally got their audio source problems fixed with their flappy bird game?
how do i fix my objects pivot? Or is it about pivot, whenever i call Transform.position its offset and adding box collider is offset too even tho its centered to 0,0,0
not a code question
also you should show the hierarchy when showing such screenshots
Well i dont see any other channel that could fit for this question
Does the learn website from unity have 2D tutorials? I've searched quite a bit but only found 3D stuff
did you read the channel descriptions ?
yes
almost everything 3D translates to 2D the same, Unity is a 3d Engine
all that changes is the physics api, and the difference is simply adding 2D at end eg (Rigidbody vs Rigidbody2D)
Ok then, ty
how can i fix it so it will highlight the button ?|
https://paste.ofcode.org/34vz9Zd5NRThSG7G2hkvmCt
is the mouse graphic blocking it..
mouse grahic ?
oh, well that was my guess.. hmm
is the actual mouse position the same as the glove cursor..
couldnt u keep it visible during the development of it
anchor is top left
just for sanity sake.. lol i couldnt think of anything
couldnt u keep it visible during the development of it what do you mean like how ?
Can someone tell me why this doesnt work, Im trying to make it play a jump animation when space is pressed and its not touching the ground layer
if (value.isPressed && myCapsuleCollider.IsTouchingLayers(LayerMask.GetMask("Ground")))
{
myrigidbody.linearVelocity += new Vector2(0f, jumpSpeed);
myAnimator.SetBool("isJumping", !myCapsuleCollider.IsTouchingLayers(LayerMask.GetMask("Ground")));```
start by putting logs
debug log?
yup
ye i did it and its printing
where did you put it
at the end
the end ?
behind
myAnimator.SetBool("isJumping", !myCapsuleCollider.IsTouchingLayers(LayerMask.GetMask("Ground")))
I meant log something useful
idk what to do
log for example !myCapsuleCollider.IsTouchingLayers(LayerMask.GetMask("Ground") in sepearte var
verify that the conditions which you have placed are being fulfilled or what you expect them to be
ok i made a variable
bool isGrounded;
and put it in debug.log( isGrounded = myCapsuleCollider.IsTouchingLayers(LayerMask.GetMask("Ground")))
its returning true every time i press jump for some reason
I would rewrite this groundcheck with a proper physics query
you want your player grounded if its face or chest touches side of a wall ?
no only when its feet are on the floor
its like 2d platformer
yes but do you know what IsTouchingLayers does?
doesnt it just return true if its touching the layer i specified?
it should, but it doesn't care if its feet or some other part
yeah i know what u mean
its just the collider
but why does it only return true when i press space
does it jump?
yeah
is it not touching ground layers mid air
i only set my platform tile map to the layer "ground" so i dont think so
so shouldn't it be true ?
wdym
if myCapsuleCollider not touching ground, is true
if it entered the jump then IsTouchingLayers = true. then it becomes false according to you
i thought it would return false whenever i jumped since its not touching the layer anymore
oh
u saying istouchinglayer returns true if its not touching the ground?
yeah you wrote ! NOT
i thought they meant the same thing
NOT false is true
ye
that was written in the bool part of the animation
so when its false and ur not touching the floor
u play the anim so it changes it to true using !
right
I hate it when I troll myself with things like that
IsTouchingLayers becomes false but you wrote ! so its sending the Animator a true bool
yes isnt that what i want
though
because i want the jump animation to start playing when im not touching the floor
but it just never plays ever
From: https://github.com/robatwilliams/decent-code?tab=readme-ov-file#naming-things
Use positive names for Booleans, and avoid negation within the name. Negative names cause double negatives, which make expressions harder to grasp (consider enabled: true vs. disabled: false). Using the word "not" has the same issue.
how did you setup the actual transitions
no i mean the inspector Idle to Jump
what about Jump to Idle ?
no exit time?
anyway keep animator window open, select your object with the animator during playmode, see whats happening in the transitions / parameters for animator
yea ive been looking at this
it never even transitions to jumping
what about the bool?
the checkmark beside the parameter isJumping doesnt get ticked
at all ? sometimes its really quick
make sure you have the correct animator referenced
not at all even when i set my jump height to like 100 and stay in the air for ages it doesnt trigger
what does this mean
oh
myAnimator how do you assign it
Animator myAnimator
and
myAnimator = GetComponent<Animator>();
ok so the script is on the same object that has this animator you shown?
yeah because i have a run and idle animation aswell
which work fine
alr most likely its that jank property, I never used it so no idea if its just going true or not
but you said log said true
only when i pressed space yeah
just use a raycast maybe? lol
you can debug the value over multiple frames maybe to see whats happening
you should store values anyway
im just gonna mvoe on from this , i just tried to implement jump anim for fun when watching a tutorial and he didnt do it
btw did you try putting the exit time on return from Jump to Idle
im ngl i have no idea what exit time does
but it did have exit time before i changed it
it waits the clip to finish playing before transitioning to the next state
i turned it to 0.3 seconds for jump to idle i dont think it did anything
cus it never even goes to
jump
i can make it jump if i change some conditions so i think its something wrong with my true and falses
if i change myAnimator.SetBool("isJumping", !myCapsuleCollider.IsTouchingLayers(LayerMask.GetMask("Ground")));
and remove the !, it never stops jumping
that means then its touching layers
or the bool stayed true
but how
yea
idk but Id read this maybe its important..
It is important to understand that checking if colliders are touching or not is performed against the last physics system update i.e. the state of touching colliders at that time. If you have just added a new Collider2D or have moved a Collider2D but a physics update has not yet taken place then the colliders will not be shown as touching. The touching state is identical to that indicated by the physics collision or trigger callbacks.
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Collider2D.IsTouchingLayers.html
i think it just stays true
btw why not just make the jump a trigger instead of bool
thats y i was confused why it kept returning true whenever i pressed space
wdym
ive never used that
bool is useful if you have Falling / or different animation while in air not grounded
oh
usually jump is a one time thing
mine typically go
Jump => Falling => Landed
Falling is only isGrounded = false
once it goes to true it plays landed animation / state
i was planning to make double jump cus there was a double jump animation
ok
ill try follow a tut online bc i dotn know any other ground check methods
are you doing 2D or 3D?
the most common ones are usually Raycast and such
ok ill see what that is
imagine a laser that can hit colliders
Vector3 origin = transform.position + offset;
isGrounded = Physics2D.Raycast(origin , Vector2.down, dist, layers))
yeah overlap circle is good actually
this guy didnt even explain tho
I JUST WANT THE DARN CAMERA TO FOLLOW THE MOUSE AND ITS GIVING ME AN ERROR 😭😭😭
better fits a capsule
!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
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 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.
@ruby steppe you got some homework todo ✍️
B-but.. where is the error
configure your IDE before you can get help
Just curious, why lock the cursor position if you want it to follow the cursor?
it's first person view code, they want to rotate the camera by moving the mouse. they just worded it poorly
Someone help me out 😔
Do what they requested
I will see myself out to download my IDE
😶
you have an IDE downloaded, you need to configure it
You already have IDE
keep the reaction image spam out of here
@ruby steppe You can stop now
What did i do ☹️
There are no memes allowed here. Thanks.
I think you just need to brush up on the rules. They're very strict on those here.
Sadly, thats rule #17
You need to be able to just follow instructions
I know java and python
Lets be realistic here
if you know java then surely you know how to solve a null reference exception. unless of course you "know" java by having just written Hello World
This is a dev server specifically for unity and a little of C#, so anything outside that scope probably goes against their rules. Also, java is pretty transferable to C# I heard
But unity script? Im cooked, fried, boiled, sautéed, reverse seared etc..
I think our default response to someone not having read the rules (because let's be real, who does), should be to let them known they're breaking the rules and gently incourage them to have another look at them.
But can you make 2 + 2 to 5 in C#
There was Java cursed code that can do it
Unity is nothing more than an API. The c# is normal Microsoft Java
I think java is only better for android but C# overall better
public static class Sum
{
public static int Add(int a, int b) => 5;
}
Sum.Add(2,2);
ez
You mean kotlin lol @keen owl
and yes, i know this isn't the same thing lol
Yes and java too
Im not built for coding 😔 time to keep studying math 😔
Kotlin is more modern ig, so yeah
can you quit the nonsense spamming and go configure your IDE
How 🤔
Links to instructions
i remember doing this once
Hey guys, got a dumb question. When I use get axis to get the input it doesnt set the value to 1, instead it gradually increases from 0. This leads my character to take a second before stopping. I dont remember this being a problem before, any ideas?
GetAxis includes input smoothing, if you want values that are just -1,0,1 for digital input then use GetAxisRaw
This proble has been killing me, thank you!
hello so my tilemap for solid objects has a composite collider with polygons but in some places polygons are not generated and my player doesn't collide with them pls help
The polygons generated are based on the physics shapes for the different tile sprites
you can edit a sprite's physics shape in the sprite editor.
I know and all of my tiles have physics shape still they aren't shown like no polygons
Ik
Hey guys can somebody help me with some coding? you see my player jumps off the first one, but i made the collider extra big. You can see the I land on the platform and then my player wont jump. Probably a problem with my ground check right? im not so proficient, so if anybody has a quick idea, or can give me a Debug,Log Object Grounded code, I would appreciate it so much!
yes almost definitely a problem with your ground check. Sounds like you don't need our help!
see #854851968446365696 for what to include when asking for help
XD IK
Are you using layers to determine what objects to jump from?
Is that lane something I can make? Like it would break the for each loop iteration or the whole method?
break exits out of the loop, it does not return from the method. are you certain you don't want a continue there instead to just skip to the next iteration of the loop?
I want it to not count itself if it appears on the list
Cause it's basically setting their aggro focus
right, but surely you don't want to stop the loop completely
Oh, so continue skips just one iteration rigth?
Great, still this is returning itself anyways, which.... shouldn't if I am breaking the loop early????
show how you have determined that
that it is returning itself despite breaking the loop. how have you determined that is what is happening
Cause it is literally the only possible method that can return a non-enemy target
again, how have you determined this
do not make assumptions. verify what is actually happening
This is the only way to set an ally target, like there is no other
how have you determined that CalculateClosestEntity is returning itself
Cause it shows in the inspector??
how about instead of relying on what you see in the inspector, you add some logs with some useful information to confirm what is happening
because with your current code, it cannot return its own gameobject, that is not possible because the variable would be null at that point if there's nothing else in the list
is there a best encryption algorithm
Everything is completely context dependent
and in gamedev, there's very little reason to encrypt anything
For what
like for saving data
Encryption algorithms have little to do with saving data.
Why would you want that
so you cant just edit the file where youre saving data
that's not a reason, that's your end goal restated
wdym?
why don't you want people editing the save file
im not making an offline game where nothing matters
Then why would you save anything that mattered on the user's machine
If it's an online game, the custody and veracity of your data should be the responsibility of your servers, not the client device
There's no encryption scheme that will prevent your players from accessing and modifying data local to their hardware. Rely on something else to prevent cheating.
thats why im verifying with lambda serverless functions
but i still need it for other parts of the game
So then what's the encryption for
well i have an offline part of the game
and i dont want it on a server so im doing some lambda checks but things like position i dont want to have to check every second because its expensive
encryption will make it harder not prevent
What you are saying doesn’t make sense to me
At some point the actions or data or whatever of the player need to go back to the server
and if they don't, they don't matter as far as cheating prevention goes.
its serverless though
You can try the advanced encryption standard library while using an IL2CPP build for further obfuscation, though i’m not sure if AES will give you what you’re looking for
i just dont get how certain encryption is better for certain things
You're saying serverless because you're using Amazon Lambda. That doesn't mean it's serverless. It just means you're not manually managing server machines
yeah but the game isnt online its single player the lambda is just some verification
thats what i mean
You wanted encryption. It depends where you will save the data, and wherever that is, you’d implement an encryption method there
Then why do you care about cheating
Do we care if people cheat in solitaire?
i mean one part of the game is single player
Cheating is a problem because it ruins the enjoyment of other players. If there are no other players who's enjoyment is ruined, it's not a problem
its still online its just a part thats not multiplayer
You're contradicting yourself
Ultimately, you can't prevent it. So this circle of "it's multiplayer but not" is going to be never ending.
im not trying to prevent it entirely
If you have a portion of your game that isn't multiplayer, it still has to have an internet connection to access the data on the server to prevent modification.
It doesn't really matter what encryption algorithm you use because if your game is able to decrypt it to do gameplay functionality, you must be providing the encryption key. Which means any halfway knowledgable player with Cheat Engine is going to get the key and decrypt the data themselves and do whatever they'd like.
So your game better just not trust any data coming from a client if you want to prevent cheating.
but you dont need to run a server
I think you're hung up on the technicality of the word "server" here
we're just talking about whatever computing resources you have under your control that operate the cloud portions of the game
If that's some "serverless" AWS Lambdas or something, so be it
the point stands
i mean theres no server like you would need for say 2 players
So one of the players is hosting the multiplayer session?
well like could you change the key ever so often
How would that help
the key goes to the client
the client has the key
Someone will write a script very quickly that uses whatever the current encryption key is, they won't hardcode it
well if you cant decrypt a common algorithm the first time it takes time to crack then you can change it like the first time you implemented it right?
its not like encryption is completely useless right
When you have the encryption key, you can decrypt whatever you want, very quickly
but games do use it though right
Very few games encrypt save files
And any online game worth its salt is not relying on client-side encryption for anti-cheat
Most online games will save data on their own servers. Typically they’ll only save superficial things like keybinds on the users PC
well i know its not a complete solution but i didnt know it was completely useless
im saving the data so it will load faster plus less writes and reads
its not a big deal though