#💻┃code-beginner
1 messages · Page 186 of 1
Just stop addressing them
no.
Because: did i ask you for a problem ? i think not.
I will, sorry, just can't stand trolls
I want to see a screenshot of your IDE so I can see whether it's configured or not, you seem to not know
also please stop dming me
Good 😄
public class PlayerMovement : MonoBehaviour
{
private Rigidbody2D rb;
private SpriteRenderer sprite;
private Animator anim;
private float dirX = 0f;
private float dirY = 0f;
[SerializeField] private float jumpForce = 12f;
[SerializeField] private float moveSpeed = 7f;
private enum MovementState { idle, running, jumping, falling, }
public bool ClimbingAllowed { get; set; }
private void Start()
{
rb = GetComponent<Rigidbody2D>();
sprite = GetComponent<SpriteRenderer>();
anim = GetComponent<Animator>();
}
private void Update()
{
dirX = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(dirX * moveSpeed, rb.velocity.y);
if (ClimbingAllowed)
{
dirY = Input.GetAxisRaw("Vertical") * moveSpeed;
}
if (Input.GetButtonDown("Jump"))
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
}
UpdateAnimationUpdate();
}
private void UpdateAnimationUpdate()
{
MovementState state;
if (dirX > 0f)
{
state = MovementState.running;
sprite.flipX = false;
}
else if (dirX < 0f)
{
state = MovementState.running;
sprite.flipX = true;
}
else
{
state = MovementState.idle;
}
if (rb.velocity.y > .1f)
{
state = MovementState.jumping;
}
else if (rb.velocity.y < -.1f)
{
state = MovementState.falling;
}
anim.SetInteger("state", (int)state);
}
private void FixedUpdate()
{
if (ClimbingAllowed)
{
rb.isKinematic = true;
rb.velocity = new Vector2(dirX, dirY);
}
else
{
rb.isKinematic = false;
rb.velocity = new Vector2(dirX, dirY);
}
}
}
!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.
psate it to external site
dont cares to me.
i am not here to gett attacket by you.
i ask for a solution, nobody can and want to help with the Package Manager.
After this, i help an other guy.
no reason to attack me
So: in this case:
i see no need to future this Conversation .
Great, well if you're posting here in future without a configured IDE you will be banned. Have fun
🤣
no need, i do not post here in Future, and i have my VStudio completly inside unity.
help others to configure her ide 😄
i am out now for this time
(First visit this channel ever here lol)
i think: we do not meet again 🤣
lol
Pfff... I have my windows entirely in unity
@barren aurora Don't send unsolicited DMs as well. Consider that as addon to the previous warning.
I want to make a trigger happen when a collision happens with an object of a specific tag. Is it a good idea to check for the tag name on collision?
Or is it slow?
That is one of the purposes of tags.
It likely isn't your limiting factor
If you can filter it previously using collision matrix that would be more optimal though
Is it all right now?
Is there no more peace ?
Guys : I've been here for the first time,
Asked one single question to which you get no answer,
and helped someone with a problem.
stop it, it has to be good for once! Or is this going on for 3 days now, that someone has to mention me all the time ?
I lived well without you until then,
You don't get any help with the Package Manager, which doesn't download anything,
and for the integration of a Java code, I'm wrong here, all good so far.
But: Apart from that, this thing is slowly coming to an end.
That's enough! You want to play a bit important, then do it.
But leave me out of it! I've lived well without you so far, and I'll continue to do so! I've never asked for code here otherwise.
So keep your head down!
!mute 176068058241171456 3d Stop spamming. Listen to moderation and advise.
smokingheadstudio was muted.
If I create a [SerializeField] and input a value, but then I change it in the inspector. Does the inspector or the script take priority? And will it automatically change respectively?
Inspector
So, there's no problem with me changing values in the inspector, other than that it might just be confusing seeing two different values?
correct. the confusing bit may be that if you add the script again it will take the value of the script at that time
ahh, I see. Is there a way to update the script with the values in the inspector, other than going into the script and manually chaning values?
yes, you can do a Reset of the component in the inspector
Okay, thank you
Wait, wouldn't that reset the values in the inspector?
Sorry, no that is the other way round, it updates the Inspector with the values from the script
Oh yeah
The inspector cannot update the script
Need some help. I'm making a power up that will temporarily increase the players speed. On the DeactiveBuff() Method, i want to make the players speed back to the original value, but I'm not sure how/where I can store it in my script
you already are doing, you just need to NOT make RegularSpeed a local variable
Hmmmmm, how would I do that?
by removing the float and declaring the variable in class scope
i'm still not sure what you mean 😦
I've removed the float, but where would I place the line?
Oh wait
where do you have your other variable declarations?
{ } is your scope.
If you declare something within a scope, it is only accessable within that scope and child scopes.
If you declare a variable within the Start method scope, it only exists until the Start method end. So you need to declare it within the class scope as Steve said
This is my code at the moment. So I should move the line from Start() into DeactivateBuff()?
no, that's good
why are you using Invoke btw?
So that I can deactivate the pickups effects after a few seconds
I meant the Invoke keyword. Just call the method
Oh, so that I can make it happen after a few seconds rather than instantly
I used BuffTime to determine how long the effects should last
Coroutine would be better
It is good as it is.
Think what would happen if you did though - you would change your regular speed every time you deactivate a buff, which doesn't make sense.. You want your regular speed to be only initialized once at Start with your initial default speed and that's it.
how do I reference the gameobject with the required script it has
what is the declaration of m4?
It's M4
what type
It's a class?
I mean I'm setting the m4's value
so you have a class called M4 ? Do you have a reference to an instance of it?
no
do you have a reference to the GameObject it is on?
or is it on the same game object as this script?
same gameObject
then ... m4 = gameObject.GetComponent<M4>();
oh wait you meant that
That would probably go on the projectile script then
the code I showed
I was trying to reference the m4 gameobject with the M4 script
you need to put this on the script that Instantiates Projectile
not on projectile itself
like this?
projectile.m4 = gameObject.GetComponent<M4>();
Big thanks man
It works
OK, now you would be better to pre reference M4 in the script by setting a variable for it in the Inspector so you can drop the GetComponent
how do I pre reference M4 in the M4 script?
is this script the M4 script?
yeah
It works
Thanks man
I am trying to set the mine active status to false, however it does not seem to work.
Any ideas?
add some debugs and then screenshot console
will do, I have got the first mien working fine however, when I get to the second mine, it doesnt
that would suggest that your reference to mine is incorrect so make sure to debug it's GetInstanceID
I get this error when on the 2nd mine.
and that line is?
so camera is null
so, how would I fix that? I have tried every way I can think.
post your full !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.
why new ?
public new CinemachineVirtualCamera camera;
that looks like a variable that should be set in the inspector but I guess it's not for mine2
all variables are set.
the error message would disagree with that
Yeah, its an issue with camera.follow = mainPlayer, the mainPlayer gameObject is a transform.
the problem is the camera variable it is null
line 115 in code you sent is mineDefusedCounter.SetActive(true);
so mineDefusedCounter is null
@rich adder good catch
cant be line 34 would give NRE
here, let me provide both scripts I am currently working with.
true, something must be different maybe from what they sent
i think I sent a line from a different script my bad!
ok cause screenshot says ,error comes from minigameMovementline 115
but that means you should also have another error on line 34
Minigame Movement: https://hatebin.com/pbjqfbhwqp
Mine Manager: https://hatebin.com/cfjhchgcbw
thats better so it is camera
possible multiple instances
Debug.log this GetInstanceID
in Start
can you write me a very basic example of code block that simulates: gravity 0 for 5 seconds gravity 1 for second?
ok, so mine manager gets a camera but movement does not
use a coroutine
can you show also where you assigned camera
I fixed it.
do you know the alarm event in gamemaker?
is it something like that
I added this line to minigame movement: camera = GameObject.FindGameObjectWithTag("Vcam").GetComponent<CinemachineVirtualCamera>();
and it seemed to have fixed it.
yes I do
I used to use game maker
okay
Coroutine is very similiar
then I set a variable in start event for corotine
then in update event i write the code
i guess
no?
is there something like corotine event?
perhaps lookup how a coroutine works first
that sounds reasonable
I fixed it, however, now the score does not go up.
the score?
I think I saw somewhere while messing around unity before there was a component that adjusted how much the player gets affected by gravity like -1000 and 1000 something like that.
I cant seem to find it now
Yeah, there is a scoreboard for when a landmine is defused.
Greetings all! How can I make this one more optimized, it rotates objects around the center. I have 20 different objects rotate around the center, for some reason it loads RAM, maybe there is a variant to do more optimally! Multiply by Time.deltaTime or just Time? The goal is to rotate objects around the axis of the object
it was around here but i may have seen it in 2d
no maybe in 2d
but also wtf is up with that mass
cant see shit dude
!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 is spaceship 😄
so is the log printing ?
which one? for the score?
the only log you shown
The score is displayed on the users screen however, on the second mine, it does not increase by the specified amount.
doesnt answer the question lol
about the log printing
Sorry 😞 phone screen
when you get on a computer copy n paste
!screenshots
No
Be mindful, if someone requests your code as text, don't send a screenshot!
also you should be using Time.deltaTime , eg RotateAround
20+ objects rotating shouldn't be an issue, if you're lagging its something else you must profile it
I agree, I'm looking for the problem myself, maybe a heavy object somewhere on stage or something
the only way to know is using the profiler, everything else is speculation
Yea, thnx 
I seem to be having an issue with the score and the way it increases, I have tried most things I can think off.
Any ideas?
Sure thing, so when a mine is defused the score displayed on the users screen is supposed to increase by 1, however on the 2nd mine it doesn't.
public Canvas parentCanvas;
private void Start()
{
//Cursor.visible = false;
}
private void Update()
{
Vector2 movePos;
RectTransformUtility.ScreenPointToLocalPointInRectangle(parentCanvas.transform as RectTransform, Input.mousePosition, parentCanvas.worldCamera, out movePos);
Vector3 mousePos = parentCanvas.transform.TransformPoint(movePos);
cursor.position = mousePos;
}
```i'm trying to make a compiuter in 3D using a canvas as the desktop. I'm trying to limit the cursor's position that it will always stay in the canvas and never get out of it. How can i do that ?
which means you've probably got another NRE somewhere
lovely! xd
After attacking once, i get this error, im unsure why this happens, cuz i destroy the object after i get the info from it
yea but its not really destroyed
unless a destroyed object still takes up space in a list?
I have indentified an issue where if you go from the mainmenu and play the game, then the landmines do not disappear when defused.
i mean that it gets replaced
you probably need to Clear targets at the end of Delayed
your list wont resize automatically
ah i see
How would I do this?
that wasn't for you
oh, xd
yup it works, thanks guys
when going from the main menu to main scene and playing it, the landmines do not want to go from active true to active false but when playing the scene without going from the menu, it works. Any ideas on why this is happening?
Hi guys. Just question if I do this correctly:
I have an enemy that has a rigidbody and a Move script. That Move function will just take the norma vector multiplies it by speed and set the velocity of the rigidbody. Now I also want to turn rotate the enemy into the direction it's facing and I'm not sure if I'm doing it wrong / more complicated then it should be. Also should it be in Update for Fixed Update?
Here is the code:
void FixedUpdate()
{
Vector2 targetDir = Target.position - transform.position;
transform.up = Target.position - transform.position;
_movement.Move(targetDir.normalized, MoveSpeed);
}
Just to make sure, this code works. The enemy is moving towards player and also turns correctly. I just want to know if this is 100 % correct since it smells a bit. My first intuition was to do like this : transform.LookAt(Target) but then my enemy completey disappears and I dont see him any more in scene or gameview 😄
Ok now I did some changes and it smells a bit less:
void FixedUpdate()
{
transform.up = Target.position - transform.position;
_movement.Move(transform.up, MoveSpeed);
}
I dont see anything about rotation here
Ah you are setting transform.up
The physics might not like that you are rotating it with transform. Could lead into oddities/missed collisions
You could get a look rotation with Quaternion.LookRotation + maybe FromToRotation, and then use that to rotate the rb with rb.MoveRotation
Usually it is cleaner to have the Z axis as your forward direction, though. Seems like yours is the Y/up direction
maybe it's 2D?
Hi, for some reason (which I am unable to figure out) the 1st landmine sets the 2nd landmine to false when it shouldn't.
The first landmine should set itself to false and the 2nd landmine should set itself to false.
I have attached both scripts that handle the landmines.
Any assistance/help would be appreciated.
minigame movement: https://hatebin.com/rvzasonowa
mine manager: https://hatebin.com/wzsjppzqof
I don't know what you mean by "sets itself to false", do you mean deactivates itself?
And I have no idea what scripts are on what objects, or when you're expecting something to happen, some context would be appreciated.
you need to find another way to do this in minigameMovement
mine = GameObject.FindGameObjectWithTag("landmine");
you have no control of the found object
as mine is in the minigameMovement hierarchy transform.parent should do it
how do i make an instantiated prefab a child of another gameobject? im making a grid and i want to instantiate each tile it generates to be a child of a canvas i have.
use the override of Instantiate that allows you to specify a perent
does that change the instantiated tile's position at all?
nope nevermind, got it, thanks!
also Im trying to make a dragging system for an object and for some reason the OnPointerDown event just isnt registering?
I have an OnPointerDown function and a debug.log in it but it doesnt work
{
Debug.Log("OnPointerDown");
}```
I have imported the EventSystems and the class has the IPointerDownHandler
is this a UI object?
no i have it on a square sprite
add a PhysicsRaycaster to your camera
should i do the 2D raycaster
tbh, I have no idea, I dont do 2D, but I would guess so
True, it probably is, didnt think of that
how do i change the color of a UI image in script? I added the UIElements package and i can make a variable for the image but theres no options for image.color
u gotta import UnityEngine.UI and then u have the right Image class
what even is the UIElements package?
are you using the ui toolkit or default ui
yea then you gotta import UnityEngine.UI and not the other one
that makes sense
UIElements is UIToolkit
where/how can I create 3d collision detection box?
I cant really find anywhere
so for example I will be able to detect with script if player is inside this box
Physics.OverlapBox if thats what you want
or Collider?
but in scene?
Collider component
make a gameobject and add a BoxCollider component to it and tick the Trigger box. and then add a script on it with "void OnTriggerEnter(Collider other)"
don't spoon feed
thanks
I thought its separated object type
like triggers > box trigger
why
colliders are components
because you spoon feeding answers is not how people learn things
whats the property for UI elements to show/hide them? For gameobjects its just setActive but i switched some things to UI and dont know how to recreate that
UI elements are also game objects
i just wanted to know how to make it
nothing more
and you have been told to, but the additional steps aren't neccesary
to mark is as trigger and to add the callback in code etc
sorry i thought its unity-talk my bad
it wasnt working for me, i want a UI image that just has a transparency to it to show/hide when my mouse enters or exits the tile but it didnt work, ill keep messing around
i know how to code didnt need that extra step
UI elements are also game objects
you can access the gameObject normally
and call SetActive() on that
that's what i said to him, to don't spoon feed you
i know but SetActive isnt working, does OnMouseEnter and OnMouseExit work on UI elements too? im not used to working with UI
ok thanks for help Ill go do this now
it is working
use IPointerEnterHandler interface
and IPoniterExitHandler
i think the opposite. you cant learn something by just staring at the problem
no one told anything about staring at the problem - just don't spoon feed people direct asnwers, make them think and lead them to correct answers instead
tell them riddles 😄
well i didnt tell him everything. the part where he detects the player inside the OnTriggerEnter method
he just asked about how to add collider
I mean, if the question is a simple one and the answer is also simple, I think is way better way of learning to just straigh tell and not go with annoying riddles
Like a visit ask where are the snacks? And you hanlde them the house blueprint
he asked how to detect with script if player is inside the box too
no he didin't ask that
ok he mentioned it
my vehicle wont go forward but only upwards when pressed w key
Im trying to make it both go forward and upwards when pressed W
that's not how it works
calculate the direction you want the vehicle to go after pressing W key
and translate into that direction
oh ok
but vector3.forward ... and vector3.up ... work
when not used with each other
i can do like i did when i first started this pathway position change and assign it to w
as i said
but what are the chances it will work together with vector3.up since vector3.up and vector3. forward dont together
calculate the direction you want to move
and move towards that direction
right now you override
your script is moving forward
and then it's moving up
overriding the forward movement
simple vector maths
calculate desired move direction, and translate into that direction
you can use Vector3.Cross function for example
yeah i know
i was just trying to show you the basic thing i was trying to do to fix the override
maybe you could help me how to write it correctly
by doing this way you wont be able to move forward
Yes, sorry, I do mean deactivates itself
while already holding A/D
if any horizontal input will be detected, you wont be able to move forward
i still don't even know what are you trying to achieve
there is plenty of movement tutorials for unity online
I can move the vehicle to right and left
and forward and backwards
i got that part
now im just trying to modify it
so as i said
calculate the direction
you want to go
and translate into that direction
Is it supposed to be only moving horizontally or vertically? Not both at the same time?
no
ill try and calculate the direction and if it wont fix it ill come back
doesn't work like you think it does
Check your parenthesis
it moves up i just need to attach it to input
that's completely different
what i told you to do
make it in only one transform.Translate
not in two
one for forward, second for up
;)
calculate the direction you want to move, and translate there
You know now that I think about it a whole bunch of programming lines end on a winking frowny face
Can't unsee
we are good 👍
the one not problem but thing is it moves up so fast so you cant actually comprehend it movingforward. it moves forward and up (I checked in inspector window)
even tho my UPSPEED is 0.1 and normal speed (for forward) is 4
It's a little weird that your vertical input is both forward and up but okay
i mean it does what I want it to do
it moves both up and forward
Im just a little surprised that even though upspeed is 1/1000 of normal speed their numbers are still relatively close
when increasing
Hello, Guys i wonder if i can make the text mesh pro animations from canvas happens after specific period of seconds (3 seconds before the animation starts)
How
is there like clamp ?
Try logging the value you're passing to Translate. See what it's moving by every frame. I think you might be running afoul of order of operations
that I can set upspeed to a max value
bro you dont have to answer like that if you dont wanna answer just dont
You can use an invoke method for the animation maybe?
i won't spoon feed you, sorry
I mean, the presence or absence of a method is very googlable
I tried to follow from YT, was pretty confusing and didn't help me
Literally just open a new tab and type "unity clamp"
you could google "how to clamp values in unity" within the same time you was writing the question here
and get answer probably much quicker
Google should always be the first stop. If that doesn't pan out, THEN come here
also #📖┃code-of-conduct
"Use provided resources and advice before requiring others teach you how things work."
You talking about me?
no
Oh ok
void function()
{
// Do textmeshpro stuff
// ^^^^
Invoke("animations", 3.0f);
}
void animations()
{
// Do animation stuff
// ^^^^^
}```
@ripe kayak ^
Omg thx alot
Imma give it a try
Btw
"Animations"
Should i change it?
Like the name

Hey there guys, i'm having troubles with animating enemies when they take damage. I'm getting "Animator is not playing an animator controller".
I'm spawning enemies prefab from a pool of object and while in play mode if i click on one of the spawned enemy i can see they've a controller attached to them.
I'm getting the warning when i start the game and when the weapon collides with them.
https://hatebin.com/fqchhzvvzo this is one of the weapon codes i'm using that should trigger the enemyPrefab.animator.
https://gyazo.com/84626b0478dd61da2ea3751637f8837f Screenshot of one of the enemyprefab spawned from the pool.
https://gyazo.com/72fa6cfffa8e01634f791801f9df2a1a Screenshot of the game animator
Why are you changing the parameter of a prefab
do i just need to animate the base enemy object?
A prefab doesn't exist, what are you expecting to happen animating something that isn't actually there
like to set the animator to the base enemy object
It's just a blueprint for copying into the scene
So, while this object is in contact with an enemy, you want to modify the blueprint such that all new enemies will be created with that parameter set?
why?
i just want the prefab to animate when it takes damage lol
but what am i asking is, should i just animate the enemy base object instead?
did you not understand? Prefabs do not exist in the Scene
do you know what a prefab is?
a copy of a gameobject?
prefab is a recipe kinda
to create instances
prefabs doesn't exists in the scene
you can create instanecs of that prefab
prefabs gets created when the game starts no?
no
How do you expect to see an animation on a prefab
whenever your code creates them
if you create them, then yes
A prefab is a file
ye
it doesn't exist
i see
There is no visible "prefab" in the scene
prefab is like a apple pie recipe
and with that recipe you can create an actual apple pie
yes
good
its great no problem. i like that you dont give directly codes but make ppl think its for our own good but sometimes googling stuff can be hard for total beginners to c#like me so its sometimes more comfrotable for me to ask here to how I could implement it to the code Im writing at that moment
i mean look at this full of stuff i dont know
time to learn them then
you have comments
for each line
okay then if prefab is just the recipe
and a big text above the code
mm i see
like you have 100 objects with animator on the scene
ye
What do you not know
and you want to animate specific object
then you animate only on THAT specific object
not all the 100 objects
ofc
mathf, that f at the end of numbers, gui.horizontal stuff gui label and so on
seems daunting at first sight
okay i understood thanks everyone
so sometimes i feel more comfortable asking here
You need to Instantiate a prefab which creates an Instance of it in the scene. The simplest way to put it
where did gui.horizontal and gui label come from?
@soft wren yeye i'm doing that already, just having problem with animations
that's not related to how to use the Clamp
but no problem sorry. Ill at least try to spend some minutes on these documentations before asking again
as a beginner you dont know that
f means float. Decimal numbers in C# are doubles by default but Unity uses floats because they take up half the space
i mean you could think and connect things
that GUI is GUI related
and Clamp() is a different function
and you have use cases in the code
gui.whatever is for making UIs in code. If you took that whole script it'd come with sliders and whatnot
You'll notice, for example, that all of those function names are hyperlinks
you can click them
Mathf is a unity struct with static methods, primarily for floating point math
It still bugs me that Mathf is a struct and not just a static class
okay yeah i realized that I just don't want our relationship to be strained because I like these help channels on unity 🙂 thats why i made these comments
i’m pretty sure they could change it without breaking anyone’s code lol
I think when they wrote it they just didn't know static classes were a thing
Math is a static class in C# System which contains static methods for math, especially with ints
What about all my public Mathf myMath; fields?
You're the one holding us all back
I like that the color in my IDE matches other struct types with similar methods, though.
The class color makes me thing of garbage
This is why we can't have nice things
Just give me static struct 😤
i would be glad if changing Mathf to a static class causes that to break.
then everyone doing dumb shit can just do better
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
UnityEngine.MonoBehaviour:.ctor ()
I'm trying to save an array of inventory objects to a file for an app, and I get this error when I try to load the array I created. It's an array of inventoryItem, which are scribtable objects with an image (sprite) component and a script attached. I'm using the Save Game Free asset
Don't create a MonoBehaviour using new. They cannot exist outside of a GameObject
I'm not using new, the save game tool is, I think? Is there another way to save objects other than saving an array containing them?
this is my test code for saving and loading the data
I very much doubt if Save Game Free can serialize/deserialize anything other than POCO's
What line is the error on
what is a POCO
Plain old C# object
An object that doesn't inherit or extend anything
Yeah it looks like this asset is not designed to work with the kind of data you are passing it. See if that asset has a support channel or forum
Can you make any reccomendations for saving an array of scriptable objects? Save data tools are expensive
https://gdl.space/enenulekef.cs having a bit of a issue here. Im trying to get the npc to attack if the distance is less then 2. but the issue is he only attacks once. then goes into running state. i dont understand becuase im never over 2 distance.
I could be wrong, but when the monster first attacks, you set the boxColliderTrigger.enabled to false. You don't turn it back to true until the player is 3.5 units away. There's nothing in the code to turn the box collider trigger back on after that first run
That box collider is for the player not the npc.
that is just a trigger collider for a dialogue system. not the attack from the npc
My rigidbody (circle) can't move close to walls. They collide to early. Help?
check for the circle collider size in the inspector
it's exactly the same as the character
what about wall collider?
what is a good way to combine rotations
like i did in translate
with +
what replaces + for rotations?
are you setting the collision offset in the inspector? @pastel patrol
and why do you have a collision offset
I followed a guide for movement
Haven't touched it in the inspector (solved)
Yo can anyone help me find some bug? Unity (version 2023.2.8f1) says I have some bug here.
I am new at this so yeah, I don't know much about it. Also it doesn't show up in functions when I want to give it to some buttons.
(Please ignore the background)
medic 🥵
Configure your !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
That's the Sniper
Where do I find it?
And where do you get the idea there is a method called GetActivateScene?
Video I have found on internet.
And it was here.
video is wrong or you copied it wrong
Read the bot message
try reading the docs instead
Oh, alright.
Thx, that could be way useful tbh.
should be the FIRST thing you do
Well, the first thing should be to configure the IDE. Then the documentation
respectfully disagree
Doesn't matter if you know the concepts if you don't have spell check to tell you what you should actually be looking for
Well it works now anyway, I just deleted whole string and did it like this.
lmaoo
I've programmed for many more years without an IDE than with one because I RTFM
I mean you literally just spelled the function name wrong - which would have been extremely obvious if your IDE was configured.
me when I refuse to use basic tools afforded to me by modern technology for no reason
Yes and you also probably programmed for more years without Internet than with but that doesn't mean you should be avoiding the basic tool use that currently exists just because it used to not be the case
It is my firm belief, the more you rely on tools the less you actually know
Why use hammers when you have fists
Kids these days don't have calloused hammer-hands they're soft and depend on tools
indeed, to their own detriment
RocketController controller = rocket.GetComponent<RocketController>();
Is this the correct way of making a reference to a script in another script?
or shall I just use public RocketController controller and drag the Script from the inspector?
what is rocket?
It's okay but maybe you ought to reference rocket as the specific component type to avoid having to get the component later
Rocket is a GameObject, which I reference before using public GameObject rocket
is it in the same heirarchy as this script?
Yea
Unless it's being referred to as a different component type that's necessary and you're not wanting to cache the specific component reference for some reason (not used enough, etc)
then direct reference via Inspector
I only need to get the value of a variable though. Is it really necessary to direct reference via inspector then?
less overhead, minimal but less
finally made it thanks everyone 🙂
alright. Thanks @languid spire and @ivory bobcat! :)
Direct reference is always preferred. Requires a bit more effort on your part as the designer but is explicit - the object will be properly referenced because you've made sure of it (get component would be implicit where it's implied that a component should be on this object else it was meant to have been a null referenced)
I've gotten footgunned by GetComponentInChildren before.
I added more components to the object and, surprise surprise, I suddenly started getting the wrong thing
Apart from runtime generated components there really is no need to use GetComponent
and even then it's suspect
I use it sparingly nowadays.
It's all about design, lots of GetComponent or, God forbid, Find, screams bad or no design
GetComponent is great. It just gets your references, which makes setting things up easier.
Just make that field of type RocketController
GetComponent isn’t slow, as some people claim. It’s only slightly slower than accessing a Dictionary to get a component at runtime.
But if I use public RocketController controller to make a reference for another script. What do I put in the field? I can't drag the script there?...
why not, you alread said it's in the same heirarchy
drag the rocket gameobject into it
Oh. Thanks!
I thought you could drag only the script
no, you drag the instance of the script which, in this case, is on the rocket game object
Ah, I see
This is the coding channel. Try asking in #💻┃unity-talk
|| An LTS version would be the accepted stable version. ||
oki
how can I convert the GameObject[] returned by findObjectsWithTag to an inventoryItem[]? I know for a fact only inventory items will be added to this array and/or tagged
You can't convert the GameObject array - but you can certainly iterate through the objects and get that component from them and put that in a new array or list
well ok - maybe i'm being pedantic. There's always cs InventoryItem[] inventoryItems = myGameObjectArray.Select(g => g.GetComponent<InventoryItem>()).ToArray();
does this look correct?
How does new Vector3(transform.forward * vertical + transform.right * horizontal) not take 3 arguments? transform.forward and transform.right are both Vector3s, in which when added together should form a new Vector3?
there is no constructor for Vector3 that takes a single Vector3
just use the result of the addition directly! there's no need to try and construct a new Vector3
Vector3 vec1 = Vector3.one;
Vector3 vec2 = new Vector3(vec1);
you're trying to do this
forEach loops don't have a page on the documentation that I can find, how do I access the iterator for it?
Oh.
So I should just do Vector3 dir = transform.forward * vertical + transform.right * horizontal;?
Correct.
alright. Thanks!
passing a Vector3 doesn't count as "three arguments" -- it's a single argument!
I guess you could do something like this if you wanted to
Vector3 vec1 = Vector3.one;
Vector3 vec2 = new Vector3(vec1.x, vec1.y, vec1.z);
but it'd be pointless
Vector3 vec1 = Vector3.one;
Vector3 vec2 = vec1;
It'd be the same outcome as doing this.
Vector3 is a struct, so you don't have a reference to an object -- you directly have the value
This would matter with a reference type.
MyClass obj1 = new MyClass();
obj2 = obj1;
obj1.foo = 123;
print(obj2.foo); // prints "123"
e.g.
I declare the dir variable in the MyInput() function. Is it possible to use it in Movement()?
cuz I get red line when I write dir
How can i make when a button is selected something happens .
how do Actions work i tried this but it didnt work:
GameManager.Instance.GameStart += PlayerSetupServerRpc;```
```cs
public static event Action GameStart;```
the instance is just this script where the action is
Are you raising that event anywhere? As in GameStart?.Invoke();
yes
private void StartGame()
{
tick = 0;
timer = 0.0f;
GameStart?.Invoke();
}```
oh thanks that was the problem i wanted to implement that func in a later time didnt think it was a problem
float angle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg;
Quaternion rotation = Quaternion.Euler(0, angle, 0);
_rigidbody.rotation = rotation;
Vector3 newPosition = transform.position + direction * moveSpeed * Time.deltaTime;
_rigidbody.MovePosition(newPosition);``` move speed is really slow. am i doing somthing wrong here. i can increase the speed but my player speed is only 5 and this is much slower
hello guys, i've got small problem, i donwnloaded animation from mixamo, and problem is that when anim is played avatar's position is changed, i want to play anim in a way that avatar's position stays the same, i turned off Root Motion, but still same...
I also have a quick question, why do I knock this cube into the floor. I am using a character controller and the cube has rigidbody physics.
Hi all, I'm using a CM VirtualCam with a script that applies a custom bounding / confiner box that I've setup using a 2D polygon collider trigger. Almost everything is functioning as I'd like however in play mode, when taking the camera to the bounds of the scene, the camera stops where it should but the transform values on the CM VirtualCam object continue changing in the editor while inputs are pressed. This leads to the camera appearing to "stick" to the bounds as when trying to move the camera to a new position it requires the transform values to catch up before releasing the camera to freely move within the bounds again. Any idea(s) what might be causing this issue?
is there a logic error in my script? i feel like there is something wrong with my jumpBuffer logic. even if theres no obvious bug i can see in game.
bounds
the meshcollider has no "size"
its as big as the mesh
Tried it, but it didn't quite work for me.
(GetComponent<MeshCollider>().sharedMesh.bounds.size.y) > 1f
RocketController.cs(42, 33): Parentheses can be removed
RocketController.cs(42, 87): Parentheses can be removed
Cannot implicitly convert type 'bool' to 'float'
Nvm I made it work ✅
guys, in my project when the cube falls from the platform it falls very slowly even if all rigidbody settings are ok, why?
"even if all rigidbody settings"
wat?
also are you using with .velocity
PinoBody.velocity = transform.forward * Speed;
but where did you put this, this line with no context doesnt help
anyway if you're using .velocity the gravity is overwritten
Sorry, I'm making some code for ML-Agent and I put this in the void OnActionRecived
alr well anytime you call .velocity you overwrite gravity or external forces, so there's that
Hey all, don't mean to interrupt any discussion.
I have what I think should be fairly simple, but I am missing something..
I am trying to set the sprite of a gameobject, but it is not working.
Here is the code:
public static class TileFactory
{
public static GameObject GenerateTile(TileType type)
{
GameObject tile = new GameObject(type.ToString()); // Init gameobject tile
SpriteRenderer spriteRenderer = tile.AddComponent<SpriteRenderer>(); // Add sprite renderer component
Sprite sprite = Resources.Load<Sprite>($"Assets/Resources/Sprites/Tiles/Sprite-Tile_{type}.png"); // change sprite based off of tile type
//Debug.Log(sprite);
spriteRenderer.sprite = sprite;
return tile;
}
}
Then just for testing, in the Start function I am creating a default tile using the following code:
void Start()
{
GameObject defaultTile = TileFactory.GenerateTile(TileType.Grass);
}
When pressing play, it will create a GameObject called Grass, as I am intending it to. But, I look at the object and the SpriteRenderer does not have the Grass sprite selected, it just says "none". Debug.Log tells me the sprite is null.
I think it might be with how i am calling the directory, but not sure. The one in the Resources.Load method is copy/pasted from the actual asset itself so not sure what else I can change it to. Unfortunately google / chatGPT has not been much of a help. What am I missing?
not working because you did not read the Resources docs
what you are missing is RTFM
true
here this one is more clear to see where you went wrong
https://docs.unity3d.com/ScriptReference/Resources.Load.html
Jesus christ, so hostile for what? I did read the manual. I am trying to load the asset from the path. I thought this was a beginner channel? I tried implementing it as stated in the manual, and even asked chat gpt for supplementary help with the method but I cant get it to work.
Nevermind then lol.
navarone was not being hostile
I mean, if you read the docs..Particuarly the Resources.Load you will see whats wrong..
idk how telling you to look at docs is hostile lol
also avoid GPT spambot, its as useful as watching paint dry
you read this did you?
you need to read the entire page, not just glance at a single line
the Resources.Load documentation is very explicit about the rules
hint : Your path is messed up
it breaks two rules, yes
hey can someone help me please. this is my first time coding. i trying to add camera controls so i can look around when walking around. i have the script which im 99% is fine, but when i test it i cant look around
post your !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 do i just paste the link?
yes
theres no errors in the script, yes its on a game object, the camera
while its true no errors can come from this script it doesn't mean there are no errors in unity console btw
many people dont have IDE configured so they dont see error until unity compiles, not saying thats the case here just something to keep in mind
wait, sorry. i just checked and i forgot i added a new camera, i put the script on the wrong camera when i made a new one, sorry for wasting your time everyone im an idiot lol
could have sworn i put it on the right camera haha i even checked but i guess i still didnt notice haha, so sorry lol
🙈
nicee. What helps in the beginning also is to explicitly declare what you're trying to modify
what do you mean?
like if you made a field for Camera camera for example, no matter where you put script as long as the field is filled you are rotating the camera
camera.transform.eulerAngles = new Vector3(pitch, yaw, 0f);
there is no guesswork
don't fret it btw, you've already done more things right in 10 minutes than most people manage in 10 days
okay i get you now. thank you so much 🙂
Hello, I have a code with camera.euleurAngles.y, but I want to generalize it to a given vector (and not the y axis). How can I get the rotation between a transform and a given vector ?
A transform is not a rotation or a vector, so your question doesn't make too much sense.
yes
What exactly are you trying to accomplish?
Euler angles is almost definitely not the right approach
Get the angle between a transform and a vector. I don't know if it makes much sense, but here the code return the camera angles from the Y axis, but I'd like to achieve this but for "any" axis, so a vector that is not (0f, 1f, 0f)
(But maybe I didn't understand the whole method)
"a transform" is a whole collection of rotation, position, various direction vectors
it's not a think you can compare with a single vector
you need to be more specific
Instead of explaining what you want your code to do, explain what you're trying to actually do
Like "I want to look at this thing"
If you want the angle between transform.forward and an arbitrary vector for examplke, that would make more sense
but you aslso don't seem to want the angle between two vectors you want the angle around a certain vector
Context would help
But yeah Digi is right - what are you actually trying to do? Not the solution you're attempting, but the actual gameplay goal
Chances are there's an easier way to do whatever
The thing is I have a character controller that is set up to move but not rotate with the ground. Like it always rotates from y axis when turning. So I used a raycast and hit.normal to make it snap to the ground, but the thing is it broke a little my moving code. I'm tweaking things here and there because a lot was depending to the Y axis, and I'm replacing it by hit.normal
Currently I have that :
You need to just project your movement direction along the surface normal
Vector3 projectedDirection = Vector3.Project(myMovementDirection, surfaceNormal);```
{
float targetAngle = Mathf.Atan2(direction.x, direction.z)*Mathf.Rad2Deg + cam.eulerAngles.y;
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle,ref turnsmooth, turntime);
transform.rotation = Quaternion.Euler(hit.normal*angle);
Vector3 moveDir = Quaternion.Euler(hit.normal*targetAngle)*Vector3.forward;
player.Move(moveDir.normalized*(speed + alt + varjump)*incline*Time.deltaTime);
}```
yeah don't use Euler here...
Ayo
wow thats amazing
But doesn't it need to be perpendicular to the normal ?
Or that's what the method does
Do you know what vector projection does?
it gives you the part of the vector that is perpendicular to the normal (on the surface of the plane)
you can then normalize that direction and do whatever else you want with it.
Ok, because I projected my moveDir but now my character doesnt move, I think I might project it earlier and normalizing it as your advicing me thanks
well you'd have to show the full code
I think it's all in the snipped I sent, but I don't understand why when I project moveDir along my ````hit.normal```, my character (on straight ground) doesn't move. Like right after it's normalized, and it should be the exact same vector because the normal is vertical
you'd have to show your new code
because the new code should be very different from the old code
like 80% of those lines of code should have gone away
oh
{
float targetAngle = Mathf.Atan2(direction.x, direction.z)*Mathf.Rad2Deg + cam.eulerAngles.y;
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle,ref turnsmooth, turntime);
transform.rotation = Quaternion.Euler(0f, angle, 0f);
Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f)*Vector3.forward;
moveDir = Vector3.Project(moveDir, hit.normal);
player.Move(moveDir.normalized*(speed + alt + varjump)*incline*Time.deltaTime);
}```
I just added the projection
Shouldn't it do the trick ?
Basic C# question. I have an abstract weapon class. I want a property MaxUpgradeTier that I dont want to set in the base class but in all classes that inherit from it. VS makes this suggestion after i declared the property like this:
public abstract int MaxUpgradeTier { get; set; }
This is what VS gives me:
public override int MaxUpgradeTier { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
How to now define a value like 10 ?
Vector3 projectedDirection = Vector3.Project(direction, hit.normal);
Vector3 moveDir = projectedDirection.normalized *(speed + alt + varjump)*incline*Time.deltaTime;
player.Move(moveDir);``` something like this
But I need it to make my character turn along the direction with the Euler no ?
Well the abstract interface wants a getter AND a seetter
Are you sure you want a setter?
The default is to throw exceptions for both accessors
replace the throw with something else
get => 10, for example
Ok i think i got it. This is what it should be right public override int MaxUpgradeTier { get => 10; }
you also probably don't want a set accessor, yes
If you JUST want a getter then change the abstract to this:
public abstract int MaxUpgradeTier { get; }```
Then in the child:
```cs
public override int MaxUpgradeTier => 10;```
ok yeah now it makes totally sense thx
what do you think about this desgin in my base class
public abstract void OnWeaponUpgrade();
And then I have this:
public void UpgradeWeapon()
{
upgradeTier++;
OnWeaponUpgrade();
}
Is this something to work with or how would you do that or is "normally" done
I would make OnWeaponUpgrade protected
My thinking is with this design, each different weapon can have its own thing happen when it upgrades itself
I think it's a good idea - just make the abstract method protected so you don't accidentally call it elsewhere
ok done - it is that only UpgradeWeapon works from outside, got it thx
Because you always want to be calling UpgradeWeapon() right?
I actually never understood the part of programming that compels you to use private, protected and all that stuff; like, if you don't really care about security and are working solo and you know what your classes and methods do, you can practically call everything public
It's to protect you from yourself
to make everything clearer and cleaner
When you write myWeapon.Up instead of one useless function and one useful function popping up in autocorrect ONLY the useful one does
this reduces cognitive load
reduces mistakes
makes your code better
Yes and why do we need shelves and cabinets we can access our things much faster if we just put it all in a pile on the floor
I DO that XD
Makes it cleaner, yeah, but also is the other side of having to be constantly reorganazing stuff cause you need access to stuff later and you don't have access over it
I think you'll find as you gain more programming experience that you are probably over weighting that cost and under weighting the cost of everything being chaos
In general there's not really a "constant" reorganization. You think more up front about what an object's external facing interface should be before you start
hi i am waching the move ment vid and now when i move my cam moves with the wasd no the moues
Oh "the movement vid"? I love that one.
he he sorry
show script you wrote
and send tutorial
can i send links
yup
play look script using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerLook : MonoBehaviour
{
public Camera cam;
private float xRotation = 0f;
public float xSensitivity = 30f;
public float ySensitivity = 30f;
// Start is called before the first frame update
public void ProcessLook(Vector2 input)
{
float mouseX = input.x;
float mouseY = input.y;
xRotation -= (mouseY * Time.deltaTime) * ySensitivity;
xRotation = Mathf.Clamp(xRotation, -80f, 80f);
cam.transform.localRotation = Quaternion.Euler(xRotation, 0, 0);
transform.Rotate(Vector3.up * (mouseX * Time.deltaTime) * xSensitivity);
}
}
player motor using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMotor : MonoBehaviour
{
private CharacterController controller;
private Vector3 playerVelocity;
private bool isGrounded;
public float speed = 5f;
public float gravity = -9.8f;
public float jumpHeight = 3f;
// Start is called before the first frame update
void Start()
{
controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
isGrounded = controller.isGrounded;
}
public void ProcessMove(Vector2 input)
{
Vector3 moveDirection = Vector3.zero;
moveDirection.x = input.x;
moveDirection.z = input.y;
controller.Move(transform.TransformDirection(moveDirection) * speed * Time.deltaTime);
playerVelocity.y += gravity * Time.deltaTime;
if (isGrounded && playerVelocity.y < 0)
playerVelocity.y = -2f;
controller.Move(playerVelocity * Time.deltaTime);
Debug.Log(playerVelocity.y);
}
public void Jump()
{
if (isGrounded)
{
playerVelocity.y = Mathf.Sqrt(jumpHeight * -3.0f * gravity);
}
}
}
why you sent the search query and not the actual tutorial you follow 🤔
also !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.
use links
was trying to add some custom inspector things to a script so its easier to use and i found this (https://discussions.unity.com/t/custom-inspector-if-bool-is-true-then-show-variable/178698) to help me. I was using the code posseted by ElijahShadbolt in it and it works properly in the inspector but whatever i set with it is reset to the default value when I run the game.
I need editor script to drag GameObject and InputField in Inspector if and only if bool is true. If bool is false then don’t show InputField and GameObject field in Inspector. If true show that field in Inspector. public bool StartTemp; if( StartTemp ) { public InputField iField; // if StartTemp is true then only show in insp...
The first video in a series where we are creating a First Person game!
In this video we look at setting up our characters movement.
I've setup a Discord!!! and I would love to have you help me start up a friendly community where we can all help each other grow as game developers!
Discord invite link:
https://discord.gg/xgKpxhEyzZ
Can't wait t...
Hey - question - why not just use NaughtyAttributes? https://dbrizov.github.io/na-docs/attributes/meta_attributes/show_hide_if.html
didnt know that was a thing ill try it
im using some UI elements for tiles and a test object for a grid placing system, and i know the layer order is based of the heiarchy, but the tiles for the grid are generated from a prefab, is there a way i can change that sorting order so the test object is always the most visible?
ok and can u send ur code but through codebin
Put it on a separate canvas with a higher depth
You really don't. When you make something it should be pretty clear whether you want it public or private. You basically never have to go back and change anything, and if you do, your IDE can literally do it for you
and how do you call ProcessLook
for some reason that isnt working, the grid tiles are always on top of the object..
I am making a 2d game (flappy bird) this is the code, 2 question.
Does it matter if it's vector3 for any specific reason when it moves to the left? Also when the object of the script is moving to the left, it only moves to a certain point, I have not givven it a stopping point. Is there any reason why it's stop at a certain distances?
this is the code I will use the green tubes to move
you dont see anything wrong here 😏
look.ProcessLook(onFoot.Movement.ReadValue<Vector2>());
I am just making some testing, this is not the final result
no not relly
show what you tried
What!
oh
Look at the names
You're passing in Movement inside Look
ofc your WASD will move camera
😏
can you even expect this to move?
it does move
+I am just experimenting
read the code
but once
the tiles for the grid generate in the Grid canvas
and the canvas has a depth of what?
And the "test" object is on which canvas and that canvas has a depth of what?
maybe follow a tutorial instead of guess work @open apex
Can I ask a monke level question?
i just saw that canvas' have a sorting layer of their own, i havent used 2D elements too much so im just blind ig
ty
why would it stop even though I never told it to stop? I understand it move once, but I never told it to stop moving
😁
Ah yeah - sorting layer. I was thinking "depth" which is for cameras
thanks for the answer
yeah i kinda just speedran adding canvases because i was replacing 2D sprites with UI elements so i didnt look too much at what canvas' have
so basically the difference between
=
and += for example
OHHHHHH
that makes sense
😁😁
yes, I still wouldn't move a gameplay object with transforms, but for learning its ok
btw unity also has a built in method transform.Translate
I would 😁 😁 😁
I guess you don't want collisions to work 🙂
I will pray to god tonight, for it to work
no worries

all fixed
lol sure
Does anyone knows how the component rotation constraint works? Cause I read the documentation, watched a video and I still don't get it
it makes an object's rotation follow another object's rotation
This? How?
Coding it like this, in theory it would make it move frame by frame. Am I right?
also guys how do i make the ground collide with the user
in a 2d game
i just added an collider for both but it didnt work
it would move it according to the amount of fps
did you try and see what behavior you got, its def not what you think it is
You add the object whose rotation you want to follow to the "sources" list
this is what the tutorial guy is telling me to do 😔
Time.deltaTime just allows everything to be consistent through diff FPS
But I just want to "clamp" its rotation, this cannot do that?
what do i use to share code again? cant find it anywhere
No - FixedUpdate is synced to the physics simulation rate. Update is once 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.
Cause it does in blender, that's why I am confused
then the tutorial is dogshit lol
thanks
i need heeelp
How can i roll the camera depending on the speed of rotation on y axis? I have been trying for 2 hours and still nothing works, my head gonna explode
this is not for that, no
😔 😔
I will just finish it
it doesn't hurt nobody
😎
"How can i roll the camera depending on the speed of rotation on y axis?"
Well for one what does that actually mean?
it only hurts you to learn the wrong way 🙂
and waste time
man nobody is helping me i guess its time to hop on chat gpt
there are other things I learn
be fucking patatient dude
Then there is no component for that? I have to do it by a script?
go on
chat gpt best tool
Show the tutorial
No there's no component for that because it's going to depend heavily on how the thing is rotating in the first place
im tryna be
it should just be moving the objects transform by eventData.delta then dividing it by the canvas scale factor (if i decide to add one), but it goes wayyyy too fast
besides your question not seeming like a code one, you haven't even shown your Setup..
How are you moving the user
how is one supposed to know whats wrong without seeing context..
if the player is rotating camera to the left, get the speed of it rotating and clamp and store that speed between 0 and for example 30degrees/sec, then compare these 0 - 30 dg/sec to 0-15 RollAngle, which is basically rotating camera on Z axis
You get what i mean?
uhh i cant i just added jumping and gravity
No one knows anything about your code right now.
what kind of game is this?
Racing?
FPS?
FPS, i want to have a very dynamic effect
I am trying on making fast paced fps retro-styled game
do u need my code for me to learn about colliding objects
so when you look left or right you tilt left or right?
When simplified, yes
but the tilt depends on rotating speed
you ask in a code related channel my man
This is the coding channel. You should maybe try asking in #💻┃unity-talk for non coding questions.
i got ignored
I mean sounds like you have it figured out. Just add an empty object parent between your camera and whatever it's normally a child of and tilt that object depending on the current X mouse delta per second
if you have scripts that move player it can be relevant to collisions yes
No, we're all just waiting for you to actually provide information
My question is, how to calculate x mouse delta per second? I have tried searching internet, youtube, even ai, nothing helps
helppppp plzz omg help in such a rush
its brokee help pluzz why everyone ignoreeeme
i just want to make the 2d character collide with the ground
theres a lot of people in discord its not really anyones fault if people are busy or accidentally scroll past the message, you can always bump your original question but i dont think guilt tripping that nobody is listening to you
provides no context or screenshots
How are you moving the character
float mouseDeltaPerSecond = Input.GetAxis("Mouse X") / Time.deltaTime;```
i cant yet
that's too easy
Then no collisions can possibly be happening because nothing is moving
ion believe its that easy
thats how it works?
Well, how do you expect a whole bunch of completely stationary objects to collide?
mate collisions are physics
No I believe they very clearly told me they aren't moving anything
and who am I to believe otherwise
I can't see their screen so all I can go off of is the information provided
nope he added jumping and gravity
ppl on internet have made some complex ass solutions, but yours is just right, thank you very much!
Yes but when I asked how they very clearly said they weren't so I have to assume that is the correct information so the problem is solved I guess ¯_(ツ)_/¯
ahh mb gotcha
but we need to know what colliders and stuff you have on the player and ground, if we cant see the stuff relating to the problem then we cant help.
now they're not in a rush anymore
i did say i added jumping but i cant move yet
How'd you manage that? Jumping without movement. Miracle of physics right there
How does something jump while remaining stationary?
but how did you add jumping? what is your script for that so we can see whats happening, what colliders did you add?
i meant movement as in left right jeez
Physicists baffled at this conundrum
we cant help if you wont show us what youre working with
At no point did I ever ask if you were moving left or right
movement can go up and down too
rigid body for character box collider for the ground
are they normal or the 2D colliders
how am i getting an error if im not even running the game... 😭
hmm hold on lemme check
well apparently this is an error from Editor mode
329 error its .......joever
yep both 2d
You are using Destroy() on a editor object
show the full stack trace
like i dont need an script for the objects to colide right?
what does an editor objecct mean..? 😰
and whats a full stack trace
not for the collision but depending on how you have your gravity set up it could affect how the colliders detect each other
Show the inspectors for both objects
maybe you are trying to destroy a prefab or something
ye i spawn a prefab then i destroy it
happened before in my project wothout a problem
then you are probably destroying the referenced prefab asset, not the instance
Are you destroying the prefab
i... didnt intend to..?
i just did what i usually do
So check your code and see
here
You can't call Destroy on a prefab
public game object, put sprite in there, initiate it, and the gameobjkect has a script that destroys itself after an animation is played
No collider
do this
var myObj = Instantiate (prefab)
Destroy(myObj)```
not
```Instantiate(prefab)
Destroy(prefab)```
should just follow a course !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
I don't know why you're showing me this
seems your guessing ur way through this
theres a rigidbody 2d
i added an collider
and no collider
oh crap i forgot that it doesnt count as a collider 💀 mb i might be stupid
wdym where
I mean where
You've sent a screenshot of the same object still with no collider
ITS THERE
no it's not
Let's take a look at the components on this object in order
Not a collider
Not a collider
Not a collider
Not a collider
oh no 😂
And that's it
man im getting cooked
You complained about collisions not working but have no collider
what do you think?
ok i fixed it yippie
Hi,
Is there a way to directly get the correct Component:
EnemyController enemy = Instantiate(_enemyPrefab, transform.position, Quaternion.identity).GetComponent<EnemyController>();
Like some unity trick, or is this "The Way"?
i thought rigid body was an collider
Make _enemyPrefab of type EnemyController
how do you figure it would get its shape from 🤔
from rigidbody
Oh wait and I can still instantiate a whole new gameobject when its of that type? awesoem
what
rigidbody gets its shape from rigidbody ?
that makes 0 sense
what made you think that
it just describes what this physics object is.
A Body that is Rigid
another question though, on the test object that drags, it drags but it either goes slower or faster than the mouse, and i wanna figure out why instead of just brute forcing some value
I need to create a function which will follow a mouse cursor and stretch two sprites, how can I start
Vector3 mousePos = Input.mousePosition; is this a good start
By creating a function that keeps track of your mouse position
void update() is a function?
What do you think
yes
but it needs the name update to be called every frame right
so how could I rename it to a different function like trackmouse
If you are asking such questions you should better watch some very basics c# tutorials
C#
okay i will thanks
could someone take a look and see why the dragging system is all wacky silly :)
You don't , you run functions *inside * the Update
would it also work with Destroy(this) in the script of the gameobject? cuz i dont destroy them in the same script that i instantiate them
so any functions i want to be used every frame i should insert there?
Destroy(this) would only destroy this which is the Script/Component
is onmousedrag() called every frame the mouse has a change in movement?
sorry i should just google some things
best you follow a course
check pins in this channel
ngl though I don't have time for that just need to make a quick game in a month and a half for school
is update and start and onmousedrag called scripting API's?
no
you dont have time to learn , ur gonnna fail then