#๐ปโcode-beginner
1 messages ยท Page 198 of 1
i think the problem was that i copied the name of the coroutine from the code you sended in here and unity thought i want to play the old coroutine
i try it now
no its not
damn
dammn...:(
The virtual camera and your character inspectors. A video of the issue might also be helpful.
Hi, I've added a particle effect to my gun but when I shoot and turn around the particle effect doesn't move with the gun, why is that?
I want the particle effect to rotate with the gun
is the particle effect a children of the gun?
yes it is
You can.
okay
It depends on the particle system settings. Don't remember which setting exactly, but this is not the right channel for this question.
Check the particle system manual page.
but make sure to set some kind of stopper in the second coroutine if first one is running in Update. I learned this hard way ๐ because if first one is run inside update method, it will call the second one each frame or so and well... that's no bueno ๐
@teal viper Nevermind fixed the issue
okay๐
@rare basin you still here?
anyways...
is this line of code? no idea how to call it... here equal to next one?
string name = 123a;
var go = Resources.Load<GameObject>("GameRes/Model/Character/" + name + "/Prefabs/model" + name);
So will it load that prefab here? Real file location: GameRes/Model/Character/123a/Prefabs/model123a.prefab ?
I guess I have to run this one and see ๐
Did you not bother to read the Resouces.Load documentation?
no. I guess I have to
good plan
I am following a video and this part doens't make sense. How will this get activted if it's in an if statement?
I did the exact same thing and even had a log in it but nothing happened
is this video wrong?
Shooting must be called from somewhere else because it's not called there
that's exactly what I am saying
I legit spend 1 hour raging over this part and tried to make sense of it
oh, okay. so it will look explicitly in Assets/Resources + that string folder, not in just Assets/+what my question was. Okay okay, I see. Already helpful ๐ Thanks
but even if it's called in update, why would the if return true?
not quite true. it will look in Assets/.../Resources/
because the Raycast hit something
can I make my own static Load.GameRes class? ๐
how does it know it hit something?
!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.
That is what Physics.Raycast does
does the object it hit has to have mesh collider and that's it?
A collider, does not have to be Mesh
Go and read the docs, that is what they are for
Hello so I have a problem. The player model keep dissapearing when when I press play.
ok
probably dont have deltatime added to some movement, its moving too fast
Pause the game and check the scene view.
do you have all the objects in the scene as a child objects?
oh it ended up there
try it out now ๐ฎ
Seems like something wrong with the animations.
i can't tell sorry very new ๐
maybe
Not the animator, but the animations themselves. Animation clips. That or the rig.
Hmmmm i wonder, because in blende the animation are all good
I might be dumb, but that's first person camera? ๐ And you expect it to be 3rd person camera?
is it?
Well, then it must be the way you're exporting them or the rig
i finally refactored all of my already refactored code into a state machine ๐
idk you tell me ๐ From what I saw it kiinda looked like it
would also kinda explain why you don't see animations )
i setup cinemachine to look at player like this
you sure the audio source isn't looping?
The loop is not checked. Also this should have resulted in atleast hearing the footsteps in idle for me too.
๐ 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.
yeah... maybe try not putting that camera into player's game object? I dunno what the problem is. I might be just dumb, but I really think it works like a 1st person camera in your case. Sorry if I'm misleading
that's what I said ๐ You ahve to put the stopper )
you mean like waitforseconds(1)?
I think you might be right it's moving but in a weird way and far from camera
private bool actionStarted = false;
//private IEnumerator YourSecondaryCoroutine()
//{
if (actionStarted)
{
yield break;
}
actionStarted = true;
//your coooode
actionStarted = false;
//}
here ^
thanks bro
I mean wrap your secondary coroutine with this one
yeah
how can i make such a code field in discord?
my player consists of many colliders and rigidbodies. it all stems from one gameobject. if i use the following code:
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Player"))
{
collision.transform.parent = transform;
}
}
it will not work. this is because it may be a different part of the player at any point. how would i use this to reference the gameobject it all stems from? pseudocode:
OnCollide { collision.hips.parent = transform}
tripple ` , then cs, and then tripple same in the end
!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.
cs lol
lol
yeap, there you go
ye
forward the collision event to the root object and handle it there.
wouldn't that mean putting a script on every single collider
On every single rb.
none of the player's colliders do not include a rigidbody
its a ragdoll
that doesn't make sense. A ragdoll consistes of many rb+ colliders and some joints.
btw great to see your coins moving towards player )
ye
If you don't have rbs, your ragdoll probably doesn't work.
what was it that worked for you in the end?
the problem was that the enemy was destroyed before the coroutine was ended
so the code were ignored
it does have rbs
i just said, none of my colliders do not include a rigidbody
ow, okay
they all have rigidbodies
show the result when you implement the stopper please
wat? They don't include rbs, but they have rbs???
That's some contradictory statement.
loot gravitating to the player after mob is killed is suuuch a nice thing that lacks in many games ๐ cudos for you on that one
okay bye
listen to the words
none of my colliders do not include a rigidbody
so there is 0 colliders
which have no rigidbodies
meaning all of them have rigidbodies
what
Okay, well that doesn't change my answer, does it?
The way you said it made me think that it was a typo or just poor wording. I see now that what you wanted to say is that all your colliders have an rb. Which, again, doesn't change what I said.
Instantiate(_bullet, _spawnPos, Quaternion.identity);
_lastShotTime = Time.time;
I have spawn point inside a gun, what rotation is used to spawn the bullet? Considered its supposed to be 0,0
Quaternion.identity meaning "no rotation"
I see
in math, identity normally means the โdo nothingโ operator
like 1 is identity under multiplication, 0 is identity under addition, and Quaternion.identity is identity for quaternion multiplication
void Start()
{
_rb = GetComponent<Rigidbody>();
_rb.velocity = transform.forward * _bulletSpeed;
}```
Why bullets fall to the ground?
This code runs on bullet spawn
disabled it now to see what happens
or gravy, always tastier
Speed too slow?
Hello, how can I attach a GameObject to another but have the attached objects transform orientation not change.
Confusion
parent constraint
if it is the parent of other objects, it is because you WANT the children to have their transforms dependent on parent
anyone? ๐ญ I've also added some checks for the animator and rigidbody to only play sound when he is moving but still. In idle i can hear one StepL and then one StepR
I forgor to add the script
otherwise you would not parent
what collider is best used for bullet?
iโm not sure if I would use a collider
I only want object B to follow object a around, so both have the same transform position but not have the same rotation if that makes sense. Object B should always stay facing up.
Its mostly for trigger, but what should be used then?
if your bullet is an instant beam, it needs no collider
if it is actually slow, then probably sphere or capsule or rectangular prism
in continuous detection mode
Whats difference between dinamyc and speculative are?
I want the red sphere to stay in the same position relative to the purple shere. I tried giving the GameObject thats child of ball and parent of Pointer a Rigidbody that only constrains it from rotating but that doesnt work.
No, now what?
sadly no
at the rate Unity staff are quitting, probably not ๐
How can you convert an AddForce into 'addrelativeforce' without actually using 'addrelativeforce'?
my guess is to multiply the force by Transform.Forward but it gives me an error, and I'm not sure if it will result in what I want anyway:
Vector3 relativForce = new Vector3(myForce * transform.forward);
Simple
relativForce = myForce * transform.forward;
you have rigidbody reference i suppose
why the new()? ur not constructing a new vector.. ur already using a transform.forward vector
Rigidbody.AddRelativeForce
he said he doesnt wanna use AddRelativeForce
Oh i noticed now
It gives an error about not being able to use * operand on two vector3s
force shouldnt be a vector (force as in ur variable force)
it should be a float or an int..
a vector * a float is totally possible
transform.forward * 10f;
Ahh okay, I'll go from there. Thank ya!
but u had the right mindset..
if u build a local vector like that. it'll still be a local force
@sweet osprey can build a TRS matrix with default scale and then multiply that by your vector if you dont want to multiply every component of your vector manually
Hello again, so i finally figure out about why the character keep flying away when hit play, but right now there's two problem. The first is that the model keep stuck under the map and can't move. Second, when I press A or D to move right or left instead of moving right or left, the model tilt right and left instead. Any help would be appreciated.
without seeing code, who knows?
How to access this? I cant serialize this component cause its not Text, TextMesh, TextMeshPro
the correct type is TMP_Text
_bulletCount.text = value.ToString(CultureInfo.InvariantCulture);
Is this correct way to change value there?
the To string part was done by compiler
any idea why my cubes colour is stuck at white? (I've waited 2 minutes to see maybe its just pure luck that it always chose white value but i dont think thats the case)
yes
Color is 0-1
so 2/3rds of all colors you generate with that Random.Range will be white
the other colors will be various transparent shades of gray, since you're applying the same value to each component of the color
50 shades of gray cube
yes thats the case
may I ask where you got the idea that a colour component could take a value between zero and three?
i dont know color codes in c sharp
im still looking it up
still dont see 0 to 3 there though
so you want Color32 not Color
i dont know what color32 is to behonest
0 to 3 is blaxk and slightly less black for color32
@timid saffron Yeah, that is correct. However this color representation is in bytes. Unity has a struct that matches this representation, it is Color32 as stated above.
0 to 3 will be hardly noticeable
i found some colour codes they are like #2df7f
Color32 is colors with values from 0 to 255
read the docs, you have been told this before
then "Color is 0-1" what does thismean?
Even then 0-3 would be very unnoticeable variants of black. a very transparent black
It is a normalized value. Imagine every component are divided by 255
The docs would tell you
So "Color" is 0-1 components, where as "Color32" components are 0-255
guess what, the docs even tell you how to work with that
Yea I acutllay found them from docs already
do you see a pattern emerging here, your refusal to read docs is making your (and our) life more difficult than it need be
original unity docs are the only ones that count
ChatGPT?
Original ones would help the best
no here
it means the maximum value you should feed into new Color is 1, and the minimum is 0
2 or 3 or 1.67 are not valid
they will just be clamped to 1
OMG
This has nothing to do with Unity.
That is not docs...
Read the docs
System.Drawing.Color is not UnityEngine.Color
I don't know if i should laugh or cry lmao
hey, @timid saffron Forget Unity, switch to Winforms
That's sooo much more needlessly complicated for normal use cases
guyz chill. one may not know where to look properly if heis a beginner
One has been told multiple times to refer unity docs
But one refuses
yeah they kinda scare me
That's why you have been told over and over where to look
You're old enough to type two words into Google:
Being a beginner is not an excuse here.
@timid saffron Unity has its way to deal with colors. You want to learn how to manipulate them within unity since all of the unity components will use that system.
Those ways are a normalized representation of (red, green, blue, alpha), aka "Color" struct, and a bytes representation, following the same order but with 0 - 255 values.
You can use either. Say you wanted to create a pure red color, with the normalized system, you would have (1f, 0f, 0f, 1f), and with the bytes system, you'd have (255, 0, 0, 255).
From that, can you infer how you'd write pure green?
It's important they know what type they would have to write
If they wrote public Bytes myColor it would not work
They need to write public Color32 myColor
@timid saffron Anyhow, yeah. As stated above by praetorblue IIRC, grays are colors where R == G == B. So just tune your RGB to even values and you'll end up with different grays.
rofl
And now we see why I corrected them saying not byte
it works
it's crap
no need to be rude
!docs
no need to write crap code
@timid saffron Yeah, but there's redundant casting. You can declare red, green and blue as bytes instead of floats.
of course it will byte can only be 0 thru 255
@languid spire This seems uncalled for. Why is everyone piling up on this guy?
have you not been following his questions over the last few days?
@languid spire I have not. I rarely come
I wondered if there was a history. If there is, then nevermind me.
Ohh my bad then
I have never met anyone who would just rather do random stuff than look at a docs page
even when that docs page is linked to them
Yeah, I understand your point
come on, you are here for a long time
there are atlesat 3-4 people daily
who prefer that
but most are not so blatant about it
fair enough
sorry ๐ am not asking again
no problem with you asking, but when someone directs you to the docs you need to go and read them.
If you are serious about being a game dev it's in your best interest
importing a variable from the script ShotgunLaunch and for some reason unity hates this script in particular and refuses to identify this script
What does the error say
Do you have a class named ShotgunLaunch
yeah, thats my script im trying to connect
Show it
show this class
ok found the error
basically, instead of the class being called "ShotgunLaunch", it was called "Player" instead
that fixed my issue
Yes, in order to use a class of a specific name that class must first exist
C# doesn't care about filenames at all, mind you
Unity is the one that demands that your class and file names match when defining MonoBehaviour and ScriptableObject types
depends on your unity version tho
not mandatory on the newest versions
Yeah, 2023.x (i believe) no longer enforces this
that seems like a recipe for mild annoyances
i had a typo'd filename for a few months
Beginners with NewBehaviour, NewBehaviour1 ... NewBehaviour10
oh god please no
Does it also allow multiple MonoBehaviours in the same script file?
I don't know how it behaves when you do that
either it's going to go by name or it's just going to refuse to find anything
that's the only reason for doing this
You reference MonoScript assets, not C# classes
the serialized data doesn't care about the C# class name at all
strictly the asset
that sounds like it would be horrid
no it doesnt
i tested that
nah, could be useful for small related classes
allowing multiple MonoBehaviour classes per script file would require additional data
which would then make it so that renaming your classes breaks your serialized data
doesnt MB need to live on a gameobject ? it would be like the siamese twins you cannot split ๐ฎ
that's not really relevant here
two MB in one file how's it not?
ah, I guess you could interpret that as some weird chimera
that'd be particularly strange
MB is a class not a script file, so making the script file name not equal the class name means they have fundamently changed something
no, nothing has changed
go grab a scene file or prefab file and look at the data in a text editor
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 194374385375701585}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4234cd2c43978e041bbe9323c195c4bd, type: 3}
I dont do 2023 until it's LTS
this is how a component gets serialized
If you search your project for that GUID, you'll find the script asset
You can completely rename a script asset, as well as rename the class it contains, and nothing changes
Unity references assets, not C# classes
and one script file is one asset, I get it
This is not the case with [SerializeReference], mind you
references:
version: 2
RefIds:
- rid: 8536178588865790522
type: {class: SoundChoiceCriteria, ns: , asm: Assembly-CSharp}
data:
choice: {fileID: 11400000, guid: cbd98f35d855a41209ee551e8b8f5a34, type: 2}
kind: 0
oh dear, not gonna go into details but I can see several attack vectors right there
i do wonder what happens if I switch these class names out
I'm thinking more of the assembly name
Sorry for the noob queston but how can I modify this so that the answer that comes back is random
for (int i = 0; i < answerButtons.Length; i++)
{
TextMeshProUGUI buttonText = answerButtons[i].GetComponentInChildren<TextMeshProUGUI>();
buttonText.text = question.GetAnswer(i);
}
send a random number from whatever range you give it , google: unity random range
additionally to what Carwash said, you want your max range to be answerButtons.Length for Range function
Okies thank you
Additionally to what both of the above said, !code for sharing code snippets
๐ 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.
Good afternoon. I have a problem with the scenes in my game. It starts on the third screen, instead of the first. On my third screen, I added a button to return to the home menu, but it is not interactive. Does anyone know how I can solve it?
you'll have to show us what this button is actually supposed to do
by showing us its inspector
and do you have Event System object
yes
check that it exists when the problem is happening
not just before you launch the game
Always Debug the event raycast system
I have one on the third screen, if I add more than one I get an error in the console
what is "the third screen"
I will record better
and if you do have Event System, observe it in Playmode it tells you exactly whats being hit , Eg the Background instead
do this first #๐ปโcode-beginner message
ok but this wasnt the broken page no?
so why are u debugging this one
this one have the event sys
ANY scene with canvas needs event system
Inspect the Event System while in playmode for the broken scene
if you dont have one then thats ur problem
the console shows an error
show error then
they are all loaded together thats why
how i solve this?
why do you have all three scenes open
i dont no, how i close?
right click it, Unload
๐ 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.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
are we supposed to guess what the problem is or wat
hol on
Quaternion modifiedRotation = Quaternion.Euler(0f, angleToEnemy + viewAxisXOffset, viewAxisYOffset) * targetRotation;
How do i turn off these Mini Map things on the right.... i cant find an answer for whatever Version im using (the most recent)
that whether i put the viw axisyoffset in the first or last part it still rolls
instead of pitching
its 3rd person camera sorry
https://hatebin.com/hrqvrkoqph
I added the spawnPointBullet and other things with serialized vector3 value. I wanted to while ingame check where should I move the object so effect spawns more outside of the gun and bullet more inside. But it doesnt matter what I do spawn pos is wierd.
"is weird" thats very descriptive
well its like only moving on 3 corners of the screen
top right bottom and top left
Then it would seem the roll is coming from targetRotation. You're applying the given euler, then rotating it by some other Quaternion
im gonna screenshot what I mean
should explain what is supposed to do instead
no one can right off the bat know whats supposed to happen instead
gimme a min im a make a gif
the x target lock is working just not the y
and use it
How would I go about creating a boundary like this, ideally Iโd want the mouse to lock once it reaches the boundary too
probably need a custom cursor so you can clamp/lock
just by changing the sprite in settings?
nvm mines workin
no youd need an object the follows the mouse cursor and use that instead so it can be clamped and whatnot
what do you mean by a custom cursor though
a gameobject that follows the cursor, and has a sprite of a mouse cursor
this acts as your game cursor so it can be clamped/locked in
you could create an edge collider out of a polygon. that'd let you just draw the shape directly, and you'd also be able to raycast against it to figure out if you're trying to stretch past the limit
thanks
that's just something that springs to mind, though. it might be awkward in practice..
I don't do much 2D stuff!
Do you sometime use the parameter Out in methods?
80% of the time
Oh ok, I've never seen people using it in videos so I though there was some drawback I wasn't aware of
generally if you need more than 1 value returned where the method return value isnt only thing you need
Yeah it's very common to need that
look at Raycast method is a great example
the method itself returns bool of success vs fail hitting collider
but the out gives you the actual hit data
I work in a typical pattern for certain items,
If(TryGetSumthing(out var somethingElse))
I try to avoid them. If I need multiple pieces of data returned, I'll create a struct, fill it, and return that.
another good example
https://docs.unity3d.com/ScriptReference/Component.TryGetComponent.html
Why is that?
just to avoid confusion. I only use the out param for OPTIONALLY returned values, like the example navarone gave.
struct or tuple is also valid return to avoid out
i dont understand this rolling
its supposed to just be going vertical and its rolling
hmm this vid is too small for me to read anything.
rolling?
nah thats zoom its supposed to do that
perhaps you should specify wtf we're looking at
its supposed to just be going vertical and its rolling
what is "it"
when i press up on y axis its supposed to pitch up and down
WHAT IS
its rolling
sorry caps
the camera
๐ Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
๐ Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
https://hastebin.com/share/pisayekene.java my script again
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
I don't see any rolling in that video? I see it going up and down a little, which looks to be caused by the animation?
Quaternion modifiedRotation = Quaternion.Euler(0f, angleToEnemy + viewAxisXOffset, viewAxisYOffset) * targetRotation; this is the line i question
but regardless whether i put viewaxisyoffset in the first or 3rd spot it still rolls one way or the other
like its not that the rolling is bad its just on the wrong axis
dont see how this is supposed to do anything vertical
Quaternion modifiedRotation = Quaternion.Euler(0f, angleToEnemy + viewAxisXOffset, viewAxisYOffset) * targetRotation; I dont see the reason for this part * targetRotation, perhaps you mean to use a "startingRotation" here?
or perhgaps just the curren rotation? transform.rotation
ya cameras are butt to figure out
if anyone could help me in physics i would appreciate it
im almost done just been stuck for 3 days on that
this would still kinda be crossposting ๐
check out https://docs.unity3d.com/ScriptReference/Quaternion.RotateTowards.html @pastel dome does alot of good stuff for ya, incluing not overshooting, speed, etc...
nah i mean the channel since i already put it there
cant write hashtag on this keyboard though
ah! checking it out
lol did you make that website
what are the chances
its posted here many times
thats how often people dont know how to ask questions in a public forum
isnt that just like how i calculate the direction to the target but for angles
like i could use that with lookrotation
is that a unique url though?
it does more than just calculate angles, it performs the rotation of the transform for you, at the speed specified, without overshooting. I'm not sure if it's good for your use-case, but I THINK it would be.@pastel dome
not sure what you mean by that lol
its a copy of this https://solhsa.com/dontask.html
you mean instead of a fixed angle that i set before just use that and add 30 degrees to the pitch
Yes, like how discord.gg or facebook.com are unique urls. Websites have those so you can navigate to them
itll go opposite my enemy?
Have we reached a generation that does not know that you can just... make a website?
full circle
Like, any person can just pay five dollars to a domain registrar and put whatever the hell they feel like somewhere
god i miss geocities
Oooooeeee
you hethern
hey hey it was free for a broke 12 year old
Everyone's so used to the walled gardens of six websites controlling the world they forget that there are literally billions of websites
don't leave out Homestead and AngelFire ๐
everything is a fucking app now ๐ฆ
angelfire! good times good times
unstoppable midi bg music FTW
probably my first exposure to hacking
using little snippets of javascript to disable the popups
๐ i felt L337
nah but id assume it would be taken already
ikr hackur
good thing we got a surplus of new domains to make up for it :D..
.com .app .web .game
etc
It is
By that website
wonder its analytics
any experts?
I'm an expert in sleep
can you help?
me
ask your actual question
Hello.
Just upgraded unity to 2021(worse decision)
and recieved an error
Did they change the name, type or just a casual error
How do I force my game to run in 16:9 when built? I need to capture footage of my game but I have a 21:9 monitor.
No i hate it many reasons lol
isn't this from the legacy advertisement package
it crashes everytime
Yeah i see "Advertisement legacy"
Well, I removed it and im installing it again
i mean
2020 never crashes for me
2021 is generally considered the best one haha.
At least since 2017
and also i prefer old logo too lol
and project file takes 1.0GB in 2021
and 400mb in 2020
Am i supposed to install something else?
Oh wow
amazing
public float movementSpeed = 5.0f;
public float rotationSpeed = 100.0f;
public float jumpForce = 8.0f;
private bool isGrounded = true;
private bool isCrouching = false;
private bool isProne = false;
private float originalHeight;
private CharacterController controller;
private Transform playerTransform;
private void Start()
{
controller = GetComponent<CharacterController>();
playerTransform = transform;
originalHeight = controller.height;
}
private void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
Vector3 moveDirection = playerTransform.forward * verticalInput + playerTransform.right * horizontalInput;
moveDirection.Normalize();
moveDirection *= movementSpeed;
if (controller.isGrounded)
{
isGrounded = true;
moveDirection.y = -gravity * Time.deltaTime;
if (Input.GetButtonDown("Jump"))
moveDirection.y = jumpForce;
}
else
{
isGrounded = false;
moveDirection.y -= gravity * Time.deltaTime;
}
if (Input.GetKeyDown(KeyCode.C))
{
if (isCrouching)
{
controller.height = originalHeight;
isCrouching = false;
}
else
{
controller.height = originalHeight * 0.5f;
isCrouching = true;
}
}
if (Input.GetKeyDown(KeyCode.Z))
{
if (isProne)
{
controller.height = originalHeight;
isProne = false;
}
else
{
controller.height = originalHeight * 0.3f;
isProne = true;
}
}
float mouseX = Input.GetAxis("Mouse X");
playerTransform.Rotate(Vector3.up, mouseX *
rotationSpeed * Time.deltaTime);
controller.Move(moveDirection * Time.deltaTime);
}
!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.
!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.
double kill
Damn poor guy
Will it require to change the names?
if ill switch to that ad mediation
wha?t code is right there
prob need to use those methods
Read the message that popped up
well..
did you read bot message?
Let's see
post it properly
You posted it incorrectly
Double kill
bruhj
if you want to get help you should not make it diffcult for those trying to help, that is why rules/guidelines are there for posting
You could always just not run ads
lol wtf
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
It's a google play project
There we go now what is the actual question
And im trying to see how it will benefit
mouse input doesnot' work
besides its only rewarded ads to not ruin user experience
what does it mean if all my vectors get underlined in red like this
are you missing a using directive?
read the error ?
yeah it is
didn't check the console since didn't think that would be an error
remove the System.Numerics namespace
lol
you just hover over it , it tells you whats wrong
I don't have
- fix usually
why does systems.numerics keep getting added randomly
They are talking to someone else
what kind of joke is that
IDE does it sometimes
Because you hit enter when it suggests it
okay. You guys checked mei code?
ohh
How come
Remove deltaTime from your mouse input
what does it mean if rl.hid failed to create a device
When people reply to a person, you can see the message they have replied to. Why, when seeing a reply to a different person than you, did you think they were talking to you
can somebody help me, look at that
means u disconnected something while engine was running
why would I remove deltatime
like headphones? cause that happened
b/c mouse delta's are already frame independent
Because you never use deltaTime with a mouse delta
that would be a device yes
because you blindly copied a tutorial that added it erroneously
Also, might be fighting between transform and CharacterController? For the rotation issue
Hi. One question, what is a normal value for Time.deltaTime...? Because idk why I feel like I am not getting a correct value...
its varies, with FPS
this is why u add sensitivity
mouseDelta's are distance the mouse travels / frame.. its already getting scaled
Around .02 but it obviously goes all over the place
yea, u can add a sensitivity modifier
but thas a constant..
its different than the deltaTime
yeah...but is this normal...?????
yes because you have a very high framerate so deltaTime is very small
but THAT small?
how do u supposed making a game controller and mouse friendly without delta time xD
.00000089 ish
why??
its been already mentioned why
is this just straight up logging Time.deltaTime or is there some math happening?
Mouse input is already doing that(frame rate independent)
Google it
But my wording should have given you a hint
"Mouse delta"
Debug.Log(Time.deltaTime);
well there you go. keep in mind that deltaTime is also scaled by the timeScale
deltaTime is doing math constantly.. ur just debugging the result of deltaTime for (that) frame
ohhhh okay that's the problem then. Thanks
Bro. It being there or not being there shouldn't have any effect on it. Nevertheless I did what you said and my mouse still does not work
yea it definately does have an effect
it may not solve ur issue.. but it is a problem
remove it first.. and then fix the next problem
I didn't say that was the issue. But it is an issue.
can I detect when an object touches an empty game object (which has a transform component)
whats up you having input issues?
You can add a trigger collider to the empty
if it has a collider sure
Bro everything is working except for the ducking mouse
And you also need a collider on the other object, and one of them must have a rigidbody
oh okay cool thanks
yep
yes
yes
And I gave you a potential reason ๐คทโโ๏ธ
maybe its the value you're reading in the input system
Removing delta time didnt work bro
So did you remove * Time.deltaTime from the mouse input
They're using old
That was not my suggestion. As I said. Lmfao
But have you done ANY debugging?
removing the deltaTime from the mouse input is regardless of ur error.. EVEN IF IT WORKED we'd still tell u to remove it
now after its removed u can find the REAL issue
why is it when i add upwards force to an object it sometimes gets ragdolled in different directions even though ive done nothing to change other axis
@prisma sail Does playerTransform have an animator?
Or other components that might be modifying its rotation
of course it does
Tf you mean 'of course it does'
does it touch anything on the way up?
nope there is nothing
of course it has an animator
It might be overriding your player's rotation
that was my guess.. it would hit something and send it off-course
There is no "of course" here...
Many people don't have one
That's not obvious at all. Usually it's good to keep the animator on a child object
Damn, like you don't even WANT help lmfao
The attitude is real
I think the animator is a far more likely issue than what I said though (cc and transform fighting)
I should have though of that, but I didn't think they would have the animator on it
it also looks like its constantly changing the z and x axis even though it isnt visually moving
@prisma sail still might not be the code just the settings or prefrences been a while since i fooled with old input system
that's how I do it bro
whats teh setup? are there any child objects parented to the thing ur moving? like whats happening?
show some code/ screenshots etc
So the answer was "no I don't" not "of course"
Maybe show the editor
Because they wanted to know if the animator was on the same object as the script you showed
heck no, it'd probably drop my IQ just openning it
haha keep that stuff secret man
Show a screenshot of the editor, with the object that has the script selected
did you debug the value of your mouse?
public float mouseX;
private void Update()
{
mouseX = Input.GetAxis("Mouse X");
Debug.Log(mouseX);
}```
just to make sure ur getting good mouse input
First step should be some debug.logs
that'd be the first thing
of course I did everything is workingas they are supposed to
Except for the mouse..?
Stop saying of course
yes
im doing the begginer course on unity, its literally just a player object with rigidbody, boxcollider and script, the script is just when space pressed add impulse force vector3.up
Which is what was being asked
if the numbers are changing the mouse input is good..
then u'd move on to ur movement code
they are bro
but if u have an animator a good guess is the animator is overwritting the movement
Alright, fuck this, i'm out lol
Won't give anyone what they ask for.
Getting snotty
Not worth it
u can't move something in code if ur moving it with animations instead..
the thing u would do.. is move the parent in code.. and move the graphics (as animation) as a child..
that way ur code doesnt care about the animation.. and the animation doesnt care about the code
bro I offered you my project
you refused
It has everything
you could ask for
easy bud you gotta be humble if you're going to get help
could u not make a compromise and try to figure it out by sending the relevant pieces of code.. back and forth and communicate?
no one has time to wait for u to upload. download a random project, open it up, and dig thru it looking for your problem..
I asked for a screenshot
and that ignores the fact that u think we just that trusting that it aint a virus or something?
I do NOT want your fucking project lmfao
I'm on my phone lol
Show the character's inspector instead, and any components it has in its children
can you show ur code and the inspector of the object ur moving?
i just checked the course videos and it seems that the other axis are also changing so it might not be my fault
but here
it could be yea
for OnTriggerEnter2D(Collider2D other) can 'other' be replaced with the reference of a specific collider to only detect that collider?
ur player is rotated 90 degree's on the Y did u know that/
yeah so it faces the correct way its not affecting it
not the issue tho, bc ur using Vector3.up
which is a world direction
so it should just go up
what
yeah
mis-ping
Sorry, wrong person
Nah, worse, I just thought it was the other guy finally showing a screenshot haha
okay one by one I will give you what you ask for
what is that site for code sharing
I will give you relevant parts
hm it seems to be fixed now (i javent changed anything)
i made a simple character the other day to help test stuff.. i run a similar code.. and it doesnt seem to do anything weird
str8 up and str8 back down
weird.. lol
!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.
pick one.. theres plenty
Then you're doing it wrong and should fix it
other is a variable name, you cannot "replace" the value inside of it. You can compare it to another Collider2D though...
void OnTriggerEnter2D(Collider2D other)
{
if (other == someColliderVariable)
// ...
}
ya, im still thinkin its an animator / code conflict
at the start the numbers go crazy but its not actually moving, but once i start jumping it goes to -0.000 and sometimes changes by 0.001
no bro people have preferences
okay. I will come back to you in a sec
Then your preference is letting the animator drive rotation instead of code in which case there is no error, working as intended. Good day
when u get the time can you show the animation clips ur using on the player?
if any of those clips change the transform of the player, thats why the code isn't moving it correctly
of course bro but they are just idle animations let me warn you.
they don't transform or translate
then what do they do? most of the time idle animations do move the position.. up and down a bit
anyone know if its ok to do this in the Update() function:
image.color = aColor;
Or should i be doing:
if(aColor != image.color) {
image.color = aColor;
}
Is there any perf difference? Does image.color setter use a unamanged function call?
you wouldnt perceive a difference in teh game..
if u set it like the first one.. its just setting it..
if u check if the color is different and then set it.. ur running a conditional..
so yea, it does more.. but i doubt it'd be a performance difference
any chance I could send in like a page of code, I want advice on where it could be more efficient
yeah but if image.color uses unmanaged function calls the marshalling and de-marshalling time has to be taken into account so you wouldn't want to call it every tick?
!code , sure use a paste-bin website.. and you'll have a link u can share
๐ 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.
not sure, tbh.. the only thing i can say is try to run code as little as possible.. like if you want to change it. check then and then change it.. i wouldnt try to check it every tick..
but i dont think it matters, its probably very very minor difference
not always bro
someone else would have to chime in..
Its hard to tell is SetVerticiesDirty() more expensive than doing that if condition check
i said most of the time.. which implies not every time
It looks like it is :\
why u being so argumentative?
do you know how to use the profiler?
yep
it moves without the mouse?
why is my project running 9 fps i have 3 objects and 2 scripts
Ok good point
Take a look at the profiler
where is that
A single script on a single object could make it freeze
!docs profiler
Dang
bro. it works with keyboard and keypad and game controller
ya thats what i mean i dont think your animations are locked to root motion then?
Bro, that's something you should've said before
doesnt say how to open on mac though
of course bro
bro I did
he was too busy being abrasive
nvm i found it
let me scroll up and find the message
whats wrong with my referencing. it says weaponfired is never used
You are changing it, but not using it anywhere
you have to say using mouse or something for old input
most of it is (others) how tf am i supposed to know what others is
sometimes u can get frame drops when ur window is minimized (and the rest of the editor is exposed/drawing) when u maximize the frames tend to go up.. but i wouldn't think that'd be a difference like u mention.. 9fps is really bad. somethings going on
Nah bro, like bro OF COURSE they are owed time and effort while being impolite. Bro
it wouldn't affect the reference's original value? it is referencing a bool in another script named weaponfire
it would be something you written most likely..
try a restart and see if it speeds up
in profiler its just rendering and others
i did a bit ago
I found it bro
Booleans are value types, not reference types.
So when you say weaponFired = weaponFire.weaponFired it creates a copy of weaponFire.weaponFired, not a reference to it
It's a different bool now
wdym
so what could i save the data type as
ive seen the data type be saved as the name of the script but i dont get that
Well, you could just always do weaponFire.weaponFired
your right
when u click a frame spike or something in the CPU part, you'll see the Player Loop/ Editor Loop etc.. u can see if any of teh scripts you wrote are taking a weirdly long time to run
Time ms
Alternatively you could make a getter property in your class:cs private bool weaponFired => weaponFire.weaponFired; So it fetches the value from the weaponFire component every time you say weaponFired
But it's not necessary @carmine sierra
Not sure what that is, maybe you got confused
I strongly recommend doing some starter C# courses so you get a decent understanding on how variables and well, everything works
ya, not sure what most of that is.. but those are some big numbers.. ngl
That might be VSync
tf is "vsync"
vertical sync.. its a feature on ur computer/monitor that tries to sync the frame rate w/ the monitors refresh rate..
so u dont get screen tearing
i have mine turned off.. so not sure how it affects unity or nething
you're playing video games and you dont know what is a vsync?
Well, check if it's even on, for starters
you can google and find out how to turn it on/ off cuz idk where it even is ngl
Even if they don't know, google exists
yup
where do i check if vsync is on
again, google
i hate google so much
yeah
he has a mac if i read correctly..
then you picked wrong thing to learn
do mac's use vsync?
Gonna be a rough programming journey if you won't search thingd
Are those animation transitions? lmfaooo
Abstract mecanim art
^ most all coder's live w/ a window of Google open in their periphial vision ๐
no way
A... phone picture of them too?
ya, thats fkn insane.. thats what i thought it was..
Through an aquarium, it seems
and he wanted to send you that project @summer stump ๐
with broken phone camera
Yeah, let me open that up, my samsung s8 should be able to do that
theres no way thats his animator.. not enough clips in the world for that kind of transitional madness
!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.
vsynk count is on every V blank
i dont get how to send the inline code
and i asked for the animation clip not the animator.. i don't care how many animations there are.. i was just wondering if any of them were modifying the position of the player character
Use that
Backticks, not apostrophes
nah thats my escape
but ill copy and paste
Tilde
public class WeaponFire : MonoBehaviour
{
[SerializeField] Camera firingCamera;
Rigidbody2D rb;
public float velocityMultiplier;
Vector3 originalPos;
Vector3 newPos;
Vector3 poschange; // newPos - originalPos
BoxCollider2D boxCollider;
[SerializeField] float gravityScale;
public GameObject weaponInstance;
[SerializeField] GameObject Shop;
Vector3 mouseWorldPosition;
[SerializeField] CircleCollider2D spawnCollider;
bool touched;
public bool weaponFired;
private Vector3 GetMousePos()
{
mouseWorldPosition = firingCamera.ScreenToWorldPoint(Input.mousePosition);
mouseWorldPosition.z = 0f;
return mouseWorldPosition;
}
void OnTriggerEnter2D(Collider2D spawnCollider)
{
if (weaponFired)
{
Debug.Log("Passed through spawn");
rb.gravityScale = gravityScale;
}
}
void MotionToCenter()
{
rb = weaponInstance.GetComponent<Rigidbody2D>();
newPos = mouseWorldPosition;
boxCollider.enabled = false;
poschange = newPos - originalPos;
rb.velocity = new Vector2(-poschange.x*velocityMultiplier,-poschange.y*velocityMultiplier);
}
void Start()
{
boxCollider = gameObject.GetComponent<BoxCollider2D>();
}
void OnMouseDown()
{
if (weaponInstance) //Checks that the weapon has spawned in
{
GetMousePos();
originalPos = mouseWorldPosition;
Debug.Log("Clicked");
}
}
void OnMouseDrag()
{
if (weaponInstance)
{
GetMousePos();
weaponInstance.transform.position = mouseWorldPosition;
}
}
void OnMouseUp()
{
if (weaponInstance)
{
weaponFired = true;
MotionToCenter();
}
}
}
~
But yeah, that may be somewhere else
it won't detect the collision
i even debugged to let me know wont debug
is it still a tilde if its not above another character?
gravity is meant to turn on when it passes the trigger collider
Huh, I am not sure
doesnt matter ;D now im peeping this #๐ปโcode-beginner message
is the boolean true? did u check the collision w/o the boolean its nested under? could that be it?
so what do i make my vsync to make my fps higher
ill start the boolean as true and then let you know the result
oh nah it's not true
vsync is like a limiter.. theres nothing to do w/ it to make ur frames higher.. but if u disable it.. then it wont limit anything.. so ur frames will run as fast as they can
it starts without gravity as intended just doesn't turn it on when intended
Set vsyncCount to 0
im not entirely sure it even is Vsync (as the issue) but i also don't know what else it would be either ^ there ya go this guy knows
"dont sync" ?
Try Application.targetFrameRate = -1.
Are you ok?
If you have nothing to contribute, please don't post anything
i turned it off and now my framerate is a solid 6-7
Did you change targetFrameRate like spawn suggested
Bro the guy asked for it
i will now
<@&502884371011731486> Trolling, shitposting
This may be the worst photo of a screen I've ever seen
Application.targetFrameRate = -1 where do i put this though
Who?
Who asked for an incomprehensible image showing nothing?
Bro this man with purple name asked for it
The guy, bro.
that post said to put it in ur Awake() function
a script thats in the scene ofc
They did not
he's a troll, time to stop feeding
Clearly
where do i find this
you mean the Awake()?
Bro scroll up he asked for animation clip
yh
If you're going to actually show something useful, show something useful. Otherwise, be quiet and stop posting.
And that is not an animation clip
i asked for an animation clip that ur using as the idle for ur player.. u havent posted that.. and you havent posted anything thats even readible..
you'd put it in a script that you have in ur game...
could be any script.
oh ok
The recent screenshot does look like keyframes in the animation window
But still wasn't asked for lol
Or was it?
I think I might use this instead of my previous go-to snarky response to these idiots instead of this one
as long as that object is in the scene. that code will run when u start the game
yooooo nice the framerate went up by 2!!
Man people have such attitude today
it was way up top, b/c before I knew his Gamepad and Keyboard was working but not his mouse, some of us was under the impression it could be teh animator overwritting the translations.. but i think we're past that now
Like wtf
If it looks LIKE something, but you can't tell, then it is abstract art ๐
ya, im not sure tbh.. if it were me i'd do a full restart (the entire pc) and check again.. if it was still bad frames i would try making a new project to test an empty scene and see if that had bad frame rates.. and then i'd probably use that information + the profiler screenshot u took earlier and try to ask some more / research what might be the issue
- if a restart fixes it - good
- if the new project fixes it - probably some bad code/ bad assets in that project
- if the new project also has bad frames - it might be Unity in general (that particular version) or maybe some settings on ur pc..
point being, id try to isolate the issue
alright im too tired so ill go to sleep and try tommorow, thank you for the help
yea np, sorry couldn't get it worked out.. but atleast tomorrow u'll be fresh and ready
Hey, Is there any better way of doing this raycast for a gun, No bullets have been made at the moment!
void RayCastForEnemy()
{
RaycastHit hit;
if (Physics.Raycast(transform.parent.position, transform.parent.forward, out hit, 1 << LayerMask.NameToLayer("Enemy")))
{
try
{
Debug.Log("Hit a enemy");
Rigidbody rb = hit.transform.GetComponent<Rigidbody>();
rb.constraints = RigidbodyConstraints.None;
rb.AddForce(transform.parent.transform.forward * 500);
}
catch { }
}
}```
I ask this as sometimes well 50% - 75% the time it doesnt even register me hitting the enemy even close up
LayerMask.GetMask instead of that 1 << ...
Not that there's a big difference
theres different raycasts andd make sure its not hitting player first
If you pass a layer mask, you also need to pass a distance. Here you're passing the mask as the distance
sphere cast
Also, no need for GetComponent, you can just do hit.collider.attachedRigidbody
I would also just null check instead of try-catch
oh wow
alright thanks @verbal dome
So i need to pass a distance too?
Yes
this block of code means that if the gameobject touches spawnCollider, and the weapon has been fired, it would change the rigidbody's gravityscale to the variable gravityscale right?#
Ah good catch, that's a classic
i just want to make sure it's correct
alright thanks so much ima work on it and try to fix the issues and make it better
affirm
it would change w/e rigidbody you have assigned as rb yea
What SPR said is the real issue, what I said were just minor improvements
Alright thanks, I will work on what SPR said and then implement the improvements
so any ideas why it is not logging it?
"passed through spawn"
in actuallity it just detects a collider/rb entering the trigger.. in ur method you don't use the Collider2D spawnCollider in that block.. so it isn't relevant.. but ya
you have to have a rigidbody for it to detect
on spawncolliders object?
on one of the two..
either the thing w/ the trigger.. or the thing entering the trigger
is OnTriggerEnter2D even called? did you debug it?
doesn't it get called automatically
How to i get my crouch to not be permeant
Debugs for the win! ^ i would def put debugs everywehre
it does under certain conditions
permanent ?
you have to write code to uncrouch it
