#๐ปโcode-beginner
1 messages ยท Page 269 of 1
from now on, thats what that error means.. it means ur trying to access something that isn't there
I have a cube that has InteractableObject
Before you continue guessing, check
(ScriptName.cs, LineNumber)
Find out which thing is null
i just checked
a prefab uh oh
Okay so did you log the three things that could be null? Which one is null?
omw
run ur checks thru code.. b/c visibily u may not see the issue. the code will str8 up tell you
how could i log the interactable object?
That error is of a particular kind. It's basically telling you that the line in your code couldn't be properly executed because the reference was null.
log selectionTransform.GetComponent<InteractableObject>()
selectionTransform.GetComponent<InteractableObject>();
It'll either return blank (null) or the component
Log that after you log selectionTransform
both interaction_text and interactableObject are null but it may be because i wrote the log in the wrong part of the code
Put the log right before the line the error is on
okay
Debug.Log($"Interaction Text: {interaction_text}");
Debug.Log($"Selection Transform: {selectionTransform}");
var interactableObject = selectionTransform.GetComponent<InteractableObject>();
var itemName = interactableObject.GetItemName();
Debug.Log($"Interactable Object: {interactableObject}");
Debug.Log($"Interactable Name: {itemName}");```
the only thing null is interaction text
well assign ur text object ๐
Then that would be the problem
could you elaborate a bit more on that pls?
maybe because its textmeshpro instead of text?
๐ฏ
Hey all! Say I have an abstract class with a virtual method in it. Can I still override it from outside without inheriting it?
yes Text and TMP_Text are not the same
using TMPro;
public class Footastic: MonoBehaviour
{
private TMP_Text interaction_text;```
just use an interface instead
How would you override something without inheriting it? What would that even do?
interface is like abstract but more modular
https://spawncampgames.itch.io/capsule-shades need some shades for ur capsule ๐
WHY DOES ANY UNITY METHODS like awake, update MAY STOP WORKING ON ALL UNITY EDITOR VERSIONS?
Its an among us
what
kinda sus if you ask me
lol
idk why
I have not seen anyone use Interfaces on the tutorial videos I watched so I was getting into using inheritance.
yeah inheritance is good sometimes but i prefer composition when possible, interface help with that
Restate the issue. We don't understand
And do it without caps
We don't know what you're talking about
sor
wait
Yeah I am kind of confused why people prefer inheritance since you can only inherit once.
w/o caps this time.. we already know ur angry
xd
not sure its preference, certain situations call one over the other
I'm pretty sure folks are bewildered by what you've said because they likely do not agree with your statement.
and where should I look for resetting my mouse position in the middle of the screen in a first person game? I cannot find anything on the internet
i think im making the reference right but it still says that it is null
generally when you lock it it snaps to middle
It can definitely be null
TextMeshPro is the world-space object. TextMeshProUGUI is the UI-space one. You can also use their shared parent class TMP_Text instead
Get component doesn't promise anything
textmeshpro is not textmeshugui
Assuming the info ui isn't null first
It never unlocks though. I have a teleport mechanic but when I teleport the destination remembers my mouse position before starting the teleportation.
Just drag the tmp component directly also. You don't need to drag the gameobject just to use GetComponent
oh you're talking about the camera view not mouse position
generally FPS locks the cursor
It works thaks
oh so I just need to reset camera position
so you mean when you teleport you want to look into another direction?
//Unlock
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
//Lock
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
Is there a way to batch change all the shaders from old asset store purchase demo scenes to URP/simple lit so I stop having purple surfaces in demo scenes ? I dont think it can be done easily from the unity editor UI so I guess some unity editor code will be neded for this ??
is your camera not parented to player?
and nothing happened
Yes there is a destination empty in my scene. When I teleport I want to face where the destination is facing. I got this done. But the up and down view do not change
there is converter yes, only works with unity shaders not custom ones
ur going to have to rotate the camera... and reset ur values for ur mouse look script
Get component attempts to acquire the wanted component that's attached to this object. If there isn't one, it'll return null instead.
Have you considered not hiding debug logs
soo ur camera doesnt snap back to ur current mouse position
so if im looking down while teleporting my rotation changes as expected but my camera view does not.
ur camera keeps the positon ur mouse is at
in what way it does not
If you've got an error later that's supposedly acquired from there then likely the component isn't on the object
what code command should I look for to google an example ? Id basically do asomething like a loop all *.mat and if 'standard' replace it with 'urp simple lit' in pseudo-code
ASFUHOASdjgfkhasuogyhaklusdfjgyhlakdjfughkl;ajhregkj hi dont really know about this fking ability learn unity 4 years....
So im looking at the ground when I initiate the teleport. My position changes, my character's rotation changes but I am still looking at the ground when I come out on destionation
youtube is only offering that I do it by hand but with hundreds of prefavs and materials that doesnt work for me
ur gonna burn bridges if u keep responding like that
yes
oh okay so you want to manually reset the camera view
ya, so ur gonna have to disable that script.. teleport.. change the values to zero out ur mouse.. and re-enable the script
So it was working the whole time, just to be clear,
You just hid the logs
Yes
Disable the script that is responsible for mouse look i see
i understand. whole fking and in a trash....................
then enable back
You can also just assign the camera view the LookDirection of the teleport-point
ya, but u may still need to change hte camera rotation.. and / or the values u have for ur mouse. depending on how ur look script works..
it may be the case that as soon as u re-enable the mouse look script it snaps back where it was
yeah worth checking that first
hm okay. I will try disabling it.
start 1 part at a time
write u a script to disable it -> teleport and -> reenable it
and go from there
all right.
I think the cam object will still be rotated, you need to assign new rotation
yea, i was under the assumption it was parented to his player..
my teleport systems always include a rotation too
even so you're rotating on the X if you teleport with X looking down, you're gonna stillbe looking down until you reset X rot
ya, true.. liek i said. it maybe all of the above situation
yea would def do one step at time
thanks for the answers I will look into those.
took me a while to figure that out.. i had a similar problem.. had to cache my mouse delta's and then add an offset to em
If it's cc, you can also use physics sync https://docs.unity3d.com/ScriptReference/Physics.SyncTransforms.html
When I tried resetting my camera controls got weird
I press W and I go backwards and such
so the mouse didnt reset the camera as soon as i enabled it.. cuz even after rotating the camera.. the mouse look took over and snapped it back..
cuz mouse delta's are just there
cause ur controller is now rotated not same direction as your cam
you not meant to interacte with teh movement whle they are disabled..
it all happens at once.. u teleport and before u realize it ur mouse controls are back
aahhh
all 1 frame.. disable -> teleport -> reenabel
I am using a coroutine
then no wait between them..
stop teleport and start teleport
uhm i wait like .5 seconds
yea at teh end..
dont wait between the enable and disable of the mouse loook
coroutine(){
disable
teleport
enable
yield return new waitfor...
}```
You need to disable and enable the component to have it update the transform. The script/execution-of-code will not stop if disabled and re-enabled
yea, i think he's got the teleporting working.. - the camera..
if its a CC u have to disable the CC and teleport and renable
What is cc Character Controller?
Ah yeah teleport works okay
So I think must do uhh Reset camera position and face the player in the camera direction
I'm pretty sure sync transform would work as well
this is the teleporting problem
if u rotate ur player during a teleport.. ur camera stays looking where the mouse tells it to
Yes that is correct
yes they both need same rotation on Y
i keep forgetting about that
imma put it on my list to do - today..
try to get it muscle memory (exposure)
thanks so much !!! it converted 90% of the assets seemingly correctly saving me a lot of problems ๐
nicee!
you'll use that super often if ur an asset junkie
Well I am using an asset. And uh i believe its got something to do with this block
public void Init(Transform character, Transform camera)
{
m_CharacterTargetRot = character.localRotation;
m_CameraTargetRot = camera.localRotation;
}
yeah I was about give up on unity because of that, frustrates me a lot having to fix someone else code/assets especially unity enterprises stuff... I just want things to start when I just created a new project...
unity needs to enforce the new style of asset in the old ones
yup, you'll probably have to re-call that function
I do that yes
my last asset i made an BIRP folder.. and an URP folder..
just so u can delete the one u dont need
looking out for my guys
same my little shitty keypad asset uses both URP and BIRP
yeah lol I figured they can just convert the materials
I bought about 500$ of assets in 2018 and regrets it very much but now that I have them might as well use them (at least the ones who didnt go free/are unmainted/dont work anymore/deprecated)
IEnumerator StartTeleport(Vector3 position, Quaternion rotation)
{
_firstPersonController.enabled = false;
_firstPersonMouseLook.enabled = false;
// _firstPersonController.disableMovement();
// _firstPersonInteraction.disableMouseLook();
transform.position = position;
transform.rotation = rotation;
StopTeleport();
yield return new WaitForSeconds(0.4f);
}
public void StopTeleport()
{
_firstPersonMouseLook.Init(transform , _myCamera.transform);
_firstPersonController.enabled = true;
_firstPersonMouseLook.enabled = true;
}
This is what it looks like now
and some of them are just so good even if very old and they were free even if they dont show up in the store now
Im passing the destination position and rotation here.
You'd need to set it to false, do your changes then set it back to true
bro, i seen ur asset yesterday.. thought about posting up my own ๐ฌ
eh to my defense it was mostly bundles assets like from humble bundle or recommendationws from game dev I spoke to IRL (like rewired)
wasn't aware that was urs lol
go for it!
I'm making better ones ๐
i wanted to make a low-poly untextured
Um sorry I dont get it
SpeedTutor has my keypad on their list of free assets for october 2023 ๐ช
but over time I realized, they go free, or they make a version X+1 making the upgrade not free, or they stop working or you realize it doesnt actually solve your problem, or if you just had followed unity learning you could have coded something better
aye!! i got listed on thier feb 2022 one
Disable the cc component, teleport then enable the cc component
I want to make one of those Door puzzles ala Skyrim but I got carried away by other projects ๐
also one of those Key pins / breaking into door locks
that 2nd needs to be made
could sell that one.. guarentee'd
Because it prohibits transform from modifying the objects orientation
because its a physics object technically so any time you try to force new position without moving physics object it still had the old position of physics object stored
but my character's rotation works fine while teleporting?
saw something like this on the asset store before0
I tried getting a code on the web to try and make this red bar follow my mouse movement but anchor to the player. But I'm not sure on how to do that and the code I saw reports an error.
ah okay all right
Well yeah as I said again movement works fine. I will disable cc and reenable it as you say.
vector3 vs vector2
put a cast
(Vector3)hammer.position
^ ur mixing two different things
the error would tell you, but its because you need to cast to vector 3
you cannot do v2 - v3
you can assign them interchangeable but not perform operation on it
float - float, int - int, vector2 - vector2
Moving with transform would be teleporting and it would likely not comply if you're using character controller
wait what so the "hammer.position" part is a Vector 3?
yes
yes
,_, is there a manual for that type of stuff
unity is a 3D engine so all the positions are 3D structs
also just return the worldpoint to a vector3
yeah just remember to mousePos.z = 0
ScreenToWorldPoint already is a vector3 you are just doing a implict cast because of the type on the LHS
also you are using a Orthographic camera right?
ScreenToWorldPoint is kinda useless if you are not
yeah its 2D i think thats default
so yeah return ScreenToWorldPoint into a Vector3
set z to what ever you need it
then do the subtraction
So this is what yall meant? I'm not really sure I'm getting many instructions at the same time
All right I did as you say. Now I just gotta reset the camera view and rotate player towards the view so controls dont mess up right?
for example this is my script where i enter/exit a vehicle
you might want to set ur z to 0
lots more to do than to just move the player
#๐ปโcode-beginner message @twilit ocean
or set z to be the same as Hammers z
How do I do that?
yeah assumed hammer was on z of 0
otherwise you will get a direction that is leaning away or towards the screen
mousePos.z = 0 but where should I add it
mousePos.z = hammer.position.z
after you get mousePos
^ float = float
!vs
If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:
โข Visual Studio (Installed via Unity Hub)
โข Visual Studio (Installed manually)
this?
btw you can just do hammer.right = Direction ?
i was trying to build a compass earlier.. and i was way over thinking it ^ that was the solution
yeah since this is 2d the look direction will not act how you want without some changes
i am getting a very wierd error with .net and i dont know a better place to ask than here. i have a image of everything for you too? ive spent 3 days trying to fix it but it still doesnt want to work. thank you in advance
are u running windowsXP?
thats win10
im runing win10
found this error
ahh.. okay lol soo ur PC says .net is installed.. but the IDE says nu uh
no my computer doesnt say its instaled
only runtimes are
check out ur weapons script on line 14
whats on line 14 ?
but i doo have a sdk instaled as you can see
something being accessed is not present
do you have a camera with the MainCamera tag
going to assume Hammer was not set in the inspector
or camera was not found
14Vector3 mousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
then its prob the camera.main or a clone script with no field assigned
then make sure Camera has mainCamera as a tag in its inspector
Camera must not be main camera
What is weapon.cs line 14
yeah you dont have a camera with Main Camera tag
so are you following VS instructions when you are using VS Code
it looks like it
obligatory: have u tried a restart?
yes
i dont know nothing about VSCode.. but id guess u missed a step..
yeah i just noticed they prompted the bot for VS but the screenshot is VSCode
hehe, tragedy
yes but it tells me to install a code sdk but there is none
VSCode is more involved than VSComm
but yeah i cant help on either, team
here
Free downloads for building and running .NET apps on Linux, macOS, and Windows. Runtimes, SDKs, and developer packs for .NET Framework, .NET, and ASP.NET.
this one?
looks available to me
yes it is availiable and thats the one ive instaled
ive tried
too but its the same problem
nah nah, visual studio is ez af to set up
VSCode is easy to configure now its in 1.0 for Unity Extension
you know what ima re-install it
Im infected ๐ฎ starting to like VScode more..
lol (โฏยฐโกยฐ)โฏ๏ธต โปโโป
the setup has me deterred for now
is it a problem to have both installed?
nah not at all
they both use the Visual Studio package in Unity
the only thing missing is Intellicode for me
๐ค i might humour the code guys and see whats the fuss
they have plugins for that dont they?
there is Intellisense but no intellicode ๐ฆ
with copilot now criticizing my searches in bing I hope copilot doesnt start to criticize that you are using other IDE in visual studio ๐ฆ
i know they do for rider
ahh okay
they have it but some reason its not working on macos at least. I think its windows only
fancy guy
For Visual Studio, make sure not to skip the work load installation step
It's the commonly missed step - it's not checked by default

Hi sorry for delay, had to help grandma. Yes apparently I didn't have a main camera because I deleted the old one by accident. But now this happened.
did u use the thing.right?
may need to use the thing.forward or -forward instead
It looks 2d
show current code
Lets say i have a AI_Firearm script with a Reload(); method, and i also have an AI_Speaker script.
Now I want the Speaker script to run a SaySentance("Reload"); method, when the Reload(); method on the firearm script is called, by subscribing to it inside of the Speaker script like an event.
How do i do this?
do u know how events work already?
show how you set up events, it should work with event fine
Ok so one thing that I'm doubtful of is where the script was made to be in. The player or the weapon, currently the script is on the player tagging the hammer to transform.
I dont have events. I just have a Reload method and a SaySentance method
did you try this first ?
Where in the code should I place that? Do I need to erase any of the pre-existing code?
replace LookRotation
You'd replace your previous rotation line
@rich adder
oh thought you said you want to subscribe to it
You told-me to replace that I replaced that...
I dont know how to even set up the events
Quaternion.Hammer!??
That's a new one!
fair enough you took it quite literal..
I meant yes the WHOLE rotation line
One can only dream
instea of Hammer.rotation =
do Hammer.right = Direction
public class AI_Firearm : MonoBehaviour
{
public delegate void ReloadEventHandler();
public event ReloadEventHandler OnReload;
public void Reload()
{
// Reload logic
// Invoke the event
OnReload?.Invoke();
}
}
or just Action
its a delegate already
Action would just be a specific predefined type of delegate
public event Action OnReload;
Ive seen people use += but it dosnt seem to work for me, probably beacuse im doing it wrong :
frm.Reload() += SaySentance("Reload")
All the functions i mentioned are voids
Same with func
public class AI_Speaker : MonoBehaviour
{
AI_Firearm firearm;
private void Awake()
{
firearm = GetComponent<AI_Firearm>();
}
private void OnEnable() => firearm.OnReload += OnFirearmReloaded;
private void OnDisable() => firearm.OnReload += OnFirearmReloaded;
private void OnFirearmReloaded()
{
//Reload and Talk
SaySentence("Reload");
}
private void SaySentence(string sentence)
{
// Talkie stuff
}
}```
the other half of my delegate event sys
now someone can share about actions.. cuz idk
no problem.. just use it as an example and u can make all ur events from it
just remember to subscribe and unsubscribe..
Ok it took-me a lot of effort not to make a joke about this. But it doesn't seem to move past falling down and staying that way.
if u don't you'll be calling events for no reason
or listening for events for no reason rather
this is the code now (hopefully correct this time)
typically you subscribe in awake() or start() and unsub on destroy or during update()
can you switch the Hammer to Local Pivot mode and not in Center
want to see something
Yea, i saw the new unity input system had something like this with the += and the => but i never knew how it actually worked
I feel kinda stupid but trying to follow a movement tutorial for a 2d character and followed it exactly but my movement is a mess
ahh, maybe true. i always use enab and disab
but i sort my execution orders when i need also
OnEnable is better
.... what's local pivot mode?
esp if u unsubscribe in OnDisable ๐
thanks Ill keep these advice in notes, my unity knowledge is old havent done it for a while and still going throught the unity learning
it shows the exact pivot of the objects
Pivot Local mode For Lyfe!
unsubbing in OnDestroy is riskier because you donโt know what is broken or not
I said update cuz sometimes you want an update to be faster and you might temporarily disconnect events in certain cases
You'd use Action or Func if you don't feel it's necessary to define the delegate. https://medium.com/@serhat21zor/c-action-vs-func-62fe917da43f
I don't , I usually use OnDisable
think you replied to wrong person :p
thanks imma read this too
where you unsub depends on intent
oop youโre right
But all these learning later I still dont know why coroutines exists ๐ฆ
like do you want to to receive events if disabled or not
I just dont get it especially vs async/Task...
for WaitForSeconds ofc ๐
unity version of Async
a lot of my monobehaviours subscribe to spawnedEntityHandler.OnEntityDeath, which is an action that gets invoked when an entity dies. And it is always better to use that sort of thing over OnDestroy
/jk
I'm not sure of what that changed but here it is.
@rich adder
IEnumerator StartTeleport(Vector3 position, Quaternion rotation)
{
_characterController.enabled = false;
_firstPersonController.enabled = false;
_firstPersonMouseLook.enabled = false;
// _firstPersonController.disableMovement();
// _firstPersonInteraction.disableMouseLook();
transform.position = position;
transform.rotation = rotation;
StopTeleport();
yield return new WaitForSeconds(0.4f);
}
public void StopTeleport()
{
_firstPersonMouseLook.Init(transform , _myCamera.transform);
_myCamera.transform.Rotate(0,0,0 );
_characterController.enabled = true;
_firstPersonController.enabled = true;
_firstPersonMouseLook.enabled = true;
}
}
I did this and it works now
although, it might have been smarter for me to use an interface for this, to call an OnEntityDeath() interface method.
put it out of playmode, then select the hammer and show the arrows for it
I understand that but I dont know when to use one besides the obvious "call is gonna take longer than a 250ms game loop" like doing animator.something on a 19s animation
What arrows?
i use it as a Sequencer
got it
the move tool arrows
so its aligned on the .right axis
bro thank you it works with
for some reason i cant explain
thats strange..
think that the solution was that. could have saved me 3 days of reserch with none other with the same problem
I wish I could just use winforms and convert to unity canvas ๐ฆ for the initial prototype UI
Direction.Normalize()
sets the lengths to 1
Where do I place that in the code?
After Direction =
I'm totally going to write this wrong but hey lemme try
z + x would equal 1.4 (longer than z is and longer than x is)
normalizing it gives u a value thats the same length.. but same direction
unity has interesting words like lerp, tween and gizmos. Before that a gizmo for me was that dude in gremlins movie
none of those are unity terms
esp lerping, is not a unity term
lerp is short for Interpolation
They're found everywhere
normalized red line would end at orange dot

jesus..
told you
(mousePos - hammer.positon).normalized;
.normalized is a property
.normalize*
you need to learn some coding it seems
lol.. Normalize(this);
could do what spawncam suggested or also
Direction = a-b;
Direction.Normalize();
when I say AFTER its implied the line underneath lol
not between
Well that could have been said beforhand. Should have exdpected since the last accident ,_, I will learn
true
im running out of tables to flip j/k ur doing fine
|| It might be normalized https://docs.unity3d.com/ScriptReference/Vector3-normalized.html ๐ ||
ugh..
ops yeah i missed a letter too on that lol
good thing i have a project just waiting for me to write more test scripts
thats what i meant.. normalizeD
the D isn't prevelant ๐
this?
do all types have a .normalized property?
isnt that just for V3 ?
lol.. typos be rampant today
Still down
ive already forgotten what ur trying to do? where should it be pointing in this image?
where is the cursor, also make sure you select hammer show its arrows
I think the mouse cursor no?
thought it would work, something is wrong obvious im not noticing
well the line def matches the direction
oooor.. does it?
wouldnt that be behind the player?
Z seems to be 0 which should be correct
This might give you more info @rich adder
whoo cosmic mirror
ohh thats jank
gotta click back into the window btw..
for the mouse to be captured
btw just for sanity check , is your Camera set to Orthographic
when u maximized i dont think u did
I'm trying to make something tha pivots in the player and follows my mouse direction
Like a pointing gun
But it will be used for physicds
ya, i see now. wasn't sure if it was supposed to point at the cursor.. but now i got it
I did click many times
maybe if I click more it will start working
๐ 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.
did you check camera thing?
{
public Transform Hammer;
public Vector3 Direction;
void Update()
{
Vector3 mousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
mousePos.z = Hammer.position.z;
Direction = mousePos - Hammer.position;
Direction.Normalize();
Hammer.right = Direction;
}
}```
click the camera expand those sections, make sure it says Orthographic
Where does it have to say that?
found it
Under Projection
The pivot point seems off
YOOOOOOOOOOOOOOOOOOOOOOOOOOOO not working as intended but it's a step towards it
the camera was the issue apparently
nice
whats not working as intented?
seems now it points to correct direction
well, have you seen the game "Getting over it".
if you mean the Pivot, you have to change that inside the Sprite editor
the climbing game?
yeah. So I heard the base mechanic is the hammer orbitating around the player than the player orbitating around the hammer when it finds ground.
Either way, how do I acess the sprite editor to change the pivot?
Or just use a Parent object to set pivot at center of player
Hey y'all, can I make questions in this channel?
I think that would be more appropiate. Any idea on how to do it?
this is a code channel so code related questions
make a child object of the player, parent the red bar to it
rotate the new parent instead of hammer
I just wanted to make sure to not mess things up on the first time I talk on this server ;-;
Just read the FAQ and pinned messages and you will be fine
When I do this Camera.main.WorldToScreenPoint(Input.mousePosition); it always gives me the same position when I click on an object, no matter where I click on said object. Got an EventSystem put and everything works smoothly (clicking on objects trigger certain events and all) but now I want to try to click n drag an object, and they're not moving cause of that problem
This
Camera.main.WorldToScreenPoint(Input.mousePosition);
should be
ScreenToWorld
We cookin :D Thanks for the help
nice! just needs a Rigidbody2D on it and ur getting there
Tried that too but when i click and drag the object it goes off of the camera view
I'll put a object with a rigidbody at the very tip.
Lemme try again actually to make sure it was that
guys do you know that glitch (if you can call it that)?
basically, my player sticks to the wall
if so it would be a pleasure to help me with that
I was thinking maybe the new Pivot parent would have rigidbody and the whole bar is the child rigidbody with collider
this way you change rotation to rb.rotation
so it moves with physics properly
make a check like capsule cast to see if the direction you want to move in isn't blocked.
you can try to just give it no friction physics material on player collider, but thats a crapshoot sometimes
Sorry, my apologies, wanted to say the ScreenToWorld does the thing I said previously
what are you trying to do , with that ? maybe there is a better way
child rigid body you say? But what would the pivot having a rigidbody change? Thought the mouse cordinates were deterministic
it will make the whole stick rigidbody, isn't that what you want?
I'm trying to drag and drop an object for now, after I can do that, I wanted to drop it in a certain object and if its not that object it goes back to its original position
are the objects sprites? or UI
They're objects, not UI, I dragged them into the hierarchy Idk if that makes them an object sprite ๐
haha yeah you have to turn off gravity and also constraint position of rigidbody
also does player have rigidbody? i believe that also needs one if you want to affect it from the stick
okay so you need a collider for it to be selectable
then use a raycast
or there is also OnMouseDown and OnMouseUp you can use
set bool to true when down
Update to follow mousepos
It does, when I froze the X Y positions of the pivot it stayed in place and didn't lock to the player also changed gravity to 0
actually dont lock position mb
I've done that already, I got other objects that react to their respective events, but the mousePosition just doesnt register
This is my code
these events work withe the Event system + canvas
also it doesnt work on colliders, unless you put a Physics2D Raycaster on the Camera
let me look at my project, its not a climbing game but my player does get affected by its arms/climb since its a rigidbody with Hinges
Mhm everything works with that, its just the mouse that is always giving the same position with the ScreenToWorldPoint
Oh, it doesnt with the 3D Physics Raycaster?
there is
but if ur colliders are 3D
This is how it looks currently with no RB on the pivot. It's too glitchy
i mean it should be and the player should slide
They are actually
you have to code that in then
lol yeaa
oh ok so yeah 3D one works fine, but if ur camera is ortho that explains issue prob
https://unity.huh.how/screentoworldpoint
(Though for 3D i personally prefer the Plane method)
isn't that just a proof that the player is blocked but he doesn't do what we want?
oh and btw i am using a character controller
no rigidbody in the project
ye not really sure on how is it even possible to fix that.
the Main Camera has this camera component
character controller will keep climbing slopes, it doesn't care about sloped surfaces. You have to code that in with some Raycasts and normal surface checking + push your own gravity
yeah prospective is tricky with ScreenToWorld
did you see the link I sent ? it explains about the camera nearClip
but it shows in the inspector that the gravity is applying (went like to 1200).
I am in a meeting rn so I saw it very lightly but after I present I will see thoroughly, thank you!
sicne its perspective i would not use ScreenToWorldPoint
use ScreenPointToRay
applying gravity alone isn't enough, you have to also push it direction opposite of slope
then use that to cast on a plane
Theres only that and ortho tho
hm.... how do I cast on a plane?
I know its fine, but yeah like Passer said use raycast and plane
did you see the link I sent? it has that Plane explanation
oh okay, have you got some video or article about coding that? if no i'm okay
ScreenPointToRay returns a ray to use and dependign on what you want to do you can use a Physics.Raycast with it or you could use the Plane class to create a plane in memory to cast agaisnt
that link from before perfectly explains hows to hook up these 2 things to solve this problem
Only for Regular slopes not something like your clip, im not used to low poly but you can probably just cleanup the collider for that
https://youtu.be/jIsHe9ARE70
okay thanks, i will look at that
Oh I noticed now! Thank you so much
I will try it in a bit, but I'll make sure to text and say if it worked, thank you for your guys' help 
just make sure the plane is facing the correct way
The plane should be faced like the canvas or the camera?
can you show your current games prospective
yeah would help to see the game it really depends on how you want things to work
my plane disappeared after switching to URP but I have a lot of other problems to fix before this ๐ฆ
It uses to be white/gray bricks on the floor
this is a coding channel
the camera looks like the first one and the canvas for the UI
which thing you are trying to drag and where
ok lets back up a sec, what are you trying to accomplish with this position from the mouse
what you want to do with it really matters for what we will cast agaisnt
This is the food menu that appears when im playing the game, the buttons for the next and previous food works cause theyre UI, but the food in between them is not (this case the fish, sorry if it doesnt show that well the light is still under work), and im trying to drag that
I dont know if the problem needs coding to fix or not. Im not omniscient/omnipotent
not all problems can be solved by clicking stuff in the inspector or in some editor menu
I see so you're trying to drag the fish ?
I'm trying to drag it to the pet, wanted to do it for the pet's mouth but I think thats too difficult for my level now, and then the object would trigger the pet's eating animation
Yup yup!
I would make Trigger around the pets mouth
so your ray / drag will know thats the Mouth area
that will get you a raycast hit and you can see if that ray hits the fish
Ohhh, like a collider for the mouth?
yeah !
once you're dragging the fish you can check with a Tag or put a component that it is indeed the mouth area
It hit!! Yooooo
Well, now you know ๐คทโโ๏ธ
It has nothing to do with code
#archived-urp would be best
#๐ปโunity-talk would be second best
Omg thank you so much I would have not thought of that at all
yeah if it shows in the event system you could just implementing the dragging of the FIsh with the event system
IDragHandler, IDropHandler on the fish
Instead of the fish object, can I do it in the gameObject that holds that object?
On the FoodHolder
Managed to polish off an issue I was having with my item moving script
Basically, when I try to use the "move item" function, if a slot was being removed, it would displace all index values higher than itself, due to the way lists automatically "collapse" removed index slots in them
So now the move-item script has a check if a slot is being removed, and if the slot being removed is a lower index than the slot it's adding something to.
It really is a shame Unity doesn't have a built in function for moving something from one index to another, as far as I know. I'm having to use "Remove" and "Insert" instead, which can be a bit finicky.
The List<T> is a C# concept, not Unity. Instead of removing and inserting, you can just assign the value of the element at the previous index to null and the value of the new index to the item (you are moving) . . .
Hello everyone , I am making a 2d turn based game and i want to do something like this :
whenever i select a unit some buttons will be displayed , each one of them is an option of what the unit can do ( Attack , Move , Wait ... )
And i want to make everything else unclickable whenever these 3 buttons are displayed ( except setting and pause menu and things like that )
the issue i'm finding here is i cannot find a way to make elements impossible to interact with whenever i am in the state where the buttons are displayed
what solution would you recommend for this please
It sounds like an array would work better since you can't remove or add elements to the collection . . .
Hi I've been trying to find where the option to change the pivot is for 20 min now with no success? Anyone got an idea where it should be?
Even the guids on the internet seem to be different from mine
I really cannot find the option to change the pivot
Do I have to make a sprite for the object to change the pivot?
u should just use an empty container then
That could be a solution. But I'd rather find out why I can't find the option to change the pivot, given it is one of the most crucial features in 2D game making.
Making an empty container to deal with it every time might make everything a mess in the long term.
But maybe it's the sprite
its part of the sprite editor
its really easy
you would make the empty container the prefab..
my models are broken help
if u spawn it in, it'd have the child set up already
did you use code to break them?
you guy know what gorilla tag is
this is not a modding server
when you get very close to them?
nope
the first thing that comes to mind is just blocking all of the other UI with an image component that covers the entire screen, but this might allow you to navigate to the other buttons with a keyboard
I'm already using this system. But, to prevent bugs I'm constantly lerping the pivot of the hammer towards the empty container.
I found the sprite editor but can't use it.
You can't make assets that refer to scene objects.
you have to click the arrow next to the texture.. to expand it
This sounds like a great place to use Canvas Groups
thats not how that works
CanvasGroup lets you set a few things for any UI elements on or beneath the component's object, including opacity and, vitally, interactability
now i cant even import models into the game
You can make the rest of your UI non-interactable
It is expanded
You have to select the asset first , then in the asset importer you have the Sprite Editor
- Canvas
- Normal UI <-- CanvasGroup goes here
- Some Button
- Combat UI
- Attack Button
- Run Button
- Normal UI <-- CanvasGroup goes here
What do you mean by "Can't import"
By making that canvas group non-interactable, you will not be able to click on "Some Button"
i forgot
Dude I alt-tabed and came back and it worked
forgot what
um tf
We are so back
Thanks for the help, but apparently it was caused by unity's quirckyness
dont drag the sprite in.. @twilit ocean the window should show the sprite u have selected
That appears to be where you've set your model's pivot in whatever 3D software it was made in
thank you , the thing is , i wanna block game objects like players and trees and other interactable objects , I thought at first about creatin a gameObject that has a very high order in layer , and i activate it whenever i want to make the elements beneath it impossible to intereact with , do you think this is a good solution ?
blender, first time
dragging it in does nothing. its just when u select it
ahh okay u got it working then
can you help me use it
Nope. !blender probably can
A supportive community for Blender artists of all levels. Share your work, ask for help, and learn from others! https://discord.com/invite/blender
yay
I need to be able to change the size of hte inventory, since I don't plan on it having limited slots, is the main issue with using an array. Lists are easier to change the length of, and easier to insert things into the middle of them, too. Either way, I managed to fix the problem by detecting whether or not an entry was being fully removed, and if it was being fully removed from a slot lower in the index than the slot it was being added to.
Yeah, I'm still stuck on this. The camera is still jittering
Obligatory Cinemachine
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MainCamera : MonoBehaviour
{
public static MainCamera singleton;
public Transform targetObject;
Rigidbody rb;
// Start is called before the first frame update
void Start()
{
MainCamera.singleton = this;
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
public void UpdatePos()
{
transform.position = targetObject.position;
transform.rotation = targetObject.rotation;
}
}
Not gonna use Cinemachine
I've rolled it back to this though
why would you not use cinemachine ?
its gonna be better than any hacky solution you do
Not gonna use Cinemachine
why
I don't see how Cinemachine is gonna magically fix the problem I'm running into.
lol, it literally does
my guy wants to slice bread with their teeth instead of a bread slicing knife
It's not magic ๐คทโโ๏ธ
It's not magic it just literally has a third-person follow component built in that has no jittering
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//using UnityEngine.Networking;
public class ActorCamera : MonoBehaviour {
public ActorBase user;
Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
public void LateUpdate () {
//This was originally rb.position
transform.position = user.transform.position;
transform.eulerAngles = new Vector3(user.lookAngle.x,user.transform.eulerAngles.y,0);
MainCamera.singleton.UpdatePos();
}
}
Bruh... this fixed it.
Obligatory "still just use cinemachine"
Not magic, just Smart ๐ lol
stiff robotic follow ๐ฉ
built in Damping ๐ฅน
Oh camera collider? yesplz
So then, what problem are you having? ๐ค
smooth melting follow
rigidbody -> cc transition
that transition was lit
lol went out feet flying
๐โโฌ
{
// Register callbacks, which are triggered when a player message is received
var callbacks = new SubscriptionEventCallbacks();
callbacks.MessageReceived += @event =>
{
Debug.Log(DateTime.Now.ToString("yyyy-MM-dd'T'HH:mm:ss.fffK"));
Debug.Log($"Got player subscription Message: {JsonConvert.SerializeObject(@event, Formatting.Indented)}");
};
callbacks.ConnectionStateChanged += @event =>
{
Debug.Log($"Got player subscription ConnectionStateChanged: {JsonConvert.SerializeObject(@event, Formatting.Indented)}");
};
callbacks.Kicked += () =>
{
Debug.Log($"Got player subscription Kicked");
};
callbacks.Error += @event =>
{
Debug.Log($"Got player subscription Error: {JsonConvert.SerializeObject(@event, Formatting.Indented)}");
};
return CloudCodeService.Instance.SubscribeToPlayerMessagesAsync(callbacks);
}
}
``` What is @event? i need to make methods so i can unsubscribe when i want
I WAS having an issue where when trying to make a "move function" that removes an item from one slot and inserts it into another, it would insert it into the "wrong" slot, because it would use List.RemoveAt, and then List.Insert, where the removal would disjoint the indexes if it happened at a smaller index value than the index it was inserting at.
What I ended up doing to fix this is to just have the game detect if the removed entry was a lower index than the added entry, and if so, to reduce the index too be added to by -1, so it still moves it into the same "slot" reletive to other items in the inventory.
because event is a taken Keyword in c#
adding @ means you can use that as variable name no problem
and gives away that theres also another variable of the same name
so you could name something public float @class
well.. not always tru.. but most times
Hello, I'm a new devlopper, I'm currently recreating the watermelon game everything is going great but now I have two problems:
1 I can't create a scoring system, let me explain, I want to create a system whose role will be to give a certain number of points when my fruits of the same level (named element, which starts from 0 to 7 to indicate the class of the fruit) collide, this one destroys the current fruit to make room for the next fruit, example element 0 with 0 = 1 so the role of the script will be to fetch from a file the fruit that has the name of element 1 to make it appear, at which point I want it to display the example score: element 0 = 5 SCORT
element 1 = 10 SCORT
element 2 = 15 SCORT
element 3 = 25 SCORT
element 4 = 30 SCORT
element 5 = 40 SCORT
element 6 = 55 SCORT
element 7 = 70 SCORT
but I can't...
2 I'd like to create a system that displays the next fruit to appear, on an image right next to it,
can you please help me?
I need help with a scoring system and displaying the next fruit.
Translated with DeepL.com (free version)
whats the rule with special characters in variable names?
_ and @ are the only two i feel comfortable using
I think symbols break it
cause they have many uses in c#
oh and @ before a string lets you not have to escape \
code Fruit :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Fruit : MonoBehaviour
{
[HideInInspector] public MoveCloud MoveCloud;
public int fruitIndex;
private void OnCollisionEnter2D(Collision2D collision)
{
var incomingGameObject = collision.gameObject;
if (!gameObject.activeSelf || !incomingGameObject.activeSelf)
return;
var fruit = incomingGameObject.GetComponent<Fruit>();
if (fruit != null)
{
if (fruit.fruitIndex == fruitIndex)
{
fruitIndex++;
if (fruitIndex > 7)
fruitIndex = 0;
GameObject nextFruit = Instantiate(MoveCloud.fruitsPrefabs[fruitIndex]);
nextFruit.transform.position = transform.position;
Fruit nextFruitScript = nextFruit.GetComponent<Fruit>();
nextFruitScript.MoveCloud = MoveCloud;
nextFruitScript.fruitIndex = fruitIndex;
incomingGameObject.SetActive(false);
Destroy(incomingGameObject);
Destroy(gameObject);
}
}
}
}
send !code properly
๐ 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 MoveCloude
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveCloud : MonoBehaviour
{
[SerializeField] private float mouvementSpeed = 5f;
[SerializeField] private float minXPosition = -2.6f;
[SerializeField] private float maxXPosition = 2.6f;
[SerializeField] private float delayBetweenFruits = 0f;
private float lastFruitTime;
private int maxFruitSpawn = 1;
private List<int> fruitElements = new List<int>();
public GameObject[] fruitsPrefabs;
void Update()
{
if (Input.GetKey(KeyCode.Q) && transform.position.x > minXPosition)
{
transform.position -= new Vector3(mouvementSpeed * Time.deltaTime, 0, 0);
}
else if (Input.GetKey(KeyCode.D) && transform.position.x < maxXPosition)
{
transform.position += new Vector3(mouvementSpeed * Time.deltaTime, 0, 0);
}
if (Input.GetKeyDown(KeyCode.Space) && Time.time - lastFruitTime > delayBetweenFruits)
{
int numFruitsToSpawn = Random.Range(0, maxFruitSpawn + 1);
for (int i = 0; i < numFruitsToSpawn; i++)
{
int currentFruitElement = GetNextFruitElement();
if (currentFruitElement != -1)
{
GameObject newFruit = Instantiate(fruitsPrefabs[currentFruitElement]);
newFruit.transform.position = transform.position;
lastFruitTime = Time.time;
Fruit newFruitScript = newFruit.GetComponent<Fruit>();
newFruitScript.MoveCloud = this;
newFruitScript.fruitIndex = currentFruitElement;
}
}
}
}
private int GetNextFruitElement()
{
int randomElement = Random.Range(0, 4);
fruitElements.Add(randomElement);
return randomElement;
}
}
@ has special meaning. It lets you use names that are keywords.
hes using a language translator. may take him a minute
!code properly
๐ 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.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveCloud : MonoBehaviour
{
[SerializeField] private float mouvementSpeed = 5f;
[SerializeField] private float minXPosition = -2.6f;
[SerializeField] private float maxXPosition = 2.6f;
[SerializeField] private float delayBetweenFruits = 0f;
private float lastFruitTime;
private int maxFruitSpawn = 1;
private List<int> fruitElements = new List<int>();
public GameObject[] fruitsPrefabs;
void Update()
{
if (Input.GetKey(KeyCode.Q) && transform.position.x > minXPosition)
{
transform.position -= new Vector3(mouvementSpeed * Time.deltaTime, 0, 0);
}
else if (Input.GetKey(KeyCode.D) && transform.position.x < maxXPosition)
{
transform.position += new Vector3(mouvementSpeed * Time.deltaTime, 0, 0);
}
if (Input.GetKeyDown(KeyCode.Space) && Time.time - lastFruitTime > delayBetweenFruits)
{
int numFruitsToSpawn = Random.Range(0, maxFruitSpawn + 1);
for (int i = 0; i < numFruitsToSpawn; i++)
{
int currentFruitElement = GetNextFruitElement();
if (currentFruitElement != -1)
{
GameObject newFruit = Instantiate(fruitsPrefabs[currentFruitElement]);
newFruit.transform.position = transform.position;
lastFruitTime = Time.time;
Fruit newFruitScript = newFruit.GetComponent<Fruit>();
newFruitScript.MoveCloud = this;
newFruitScript.fruitIndex = currentFruitElement;
}
}
}
}
private int GetNextFruitElement()
{
int randomElement = Random.Range(0, 4);
fruitElements.Add(randomElement);
return randomElement;
}
}
please USE LINKS for large code
these are not good for viewing comfortably on phone scrolling back n forth
lol different person.. crossposting his code in a block
tried to help him
we need dyno to detect if you're adding like more than 6 lines inside `
cs
code NextFruit
using UnityEngine;
using UnityEngine.UI;
public class NextFruitUI : MonoBehaviour
{
public Image[] fruitImages;
void Start()
{
foreach (Image fruitImage in fruitImages)
{
fruitImage.enabled = false;
}
UpdateNextFruit();
}
public void UpdateNextFruit()
{
int nextFruitIndex = Random.Range(0, fruitImages.Length);
fruitImages[nextFruitIndex].enabled = true;
}
}
we dont need all your scripts either.. but now that i say that.. why is MoveCloud spawning fruits?
๐คฆโโ๏ธ
mission failed
Stop pasting scripts into the chat and read the bot message. You need to share large blocks of code using a code-sharing site linked in the bot message.
add " ``` " before and after the code
ah ok sorry
okk
or oooon site
stop suggesting that for large code
https://hatebin.com/jajwgclfme > paste
i said that to help him understand how it works
cuz he didn't know how to use it
Stop sending large code in the channel, use a paste or bin site as previously asked by others . . .
the bot explained everything , they just need to read it
You just moved up (hidden) everyone else's question(s) for help . . .
I apologize because I don't speak English very well so I have to go through a translator... I didn't quite understand, I'm sorry.
no worries, just repost your code as a hyperlink (using one of those websites linked above) and your original question again
ok thx
Hello, I'm a new devlopper, I'm currently recreating the watermelon game everything is going great but now I have two problems:
1 I can't create a scoring system, let me explain, I want to create a system whose role will be to give a certain number of points when my fruits of the same level (named element, which starts from 0 to 7 to indicate the class of the fruit) collide, this one destroys the current fruit to make room for the next fruit, example element 0 with 0 = 1 so the role of the script will be to fetch from a file the fruit that has the name of element 1 to make it appear, at which point I want it to display the example score: element 0 = 5 SCORT
element 1 = 10 SCORT
element 2 = 15 SCORT
element 3 = 25 SCORT
element 4 = 30 SCORT
element 5 = 40 SCORT
element 6 = 55 SCORT
element 7 = 70 SCORT
but I can't...
2 I'd like to create a system that displays the next fruit to appear, on an image right next to it,
link code MoveCloud : https://hatebin.com/zsbnosrzqm
Link code Fruit: https://hatebin.com/qdfjrlaooc
can you please help me?
AI code :\
idk, i used to write alot of comments when i first learning.. could be not
a little because, there are things I didn't manage to do or that I didn't find on youtube
gottem
self-snitching
you would nee to create a queue of the next item
this is gonna be hard to explain though cause of the language barrier
facts.. might as well long-format it
isn't there a solution?
you'll need a queue or get ur fruits 2 ahead of current
no way to randomize it and predict it at the same time
okkk
yes Randomize 2pieces piece first, or randomize the whole lineup and put it in a list.
that's what I told myself too, but I didn't know how to do it.
i think a buffer/queue better.. cuz u'd be chasing the dragon with the 2 piece idea
yeah agreed
I deleted my msg cause i realized Queue would not be good, they need List or array
the next piece and the one after..
once u swap pieces.. u randomize and grab the new one to fill the last ones place
so they can access the second
if I've understood correctly, I have to manage to arrange 3 ramdon fruits in advance? and then manage to display them?
that or you can just generate the whole list ahead of time
the next piece and the one after
also why storing fruits as int
store them as Fruit
public List<Fruit> fruitPrefabs // possibles to spawn
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class WelcomeSceneGameManager : MonoBehaviour
{
// Start is called before the first frame update
public AudioClip audioClip; // creating variable for audio
private AudioSource audioSource;
void Start()
{
audioSource = gameObject.AddComponent<AudioSource>(); //taking link component
audioSource.clip = audioClip; // assign variable to component
audioSource.loop = true;
audioSource.Play(); //play
}
// Update is called once per frame
void Update()
{
}
public void click()
{
SceneManager.LoadScene(1);
}
}

scenes?
Debug.Log inside click method
make sure it runs
What calls click
New scene
do u have scenes in ur build settings?
What is New scene
why is scenemanager not working properly, Normally it should be a different colour if its working but its just plain white and not doing anything
Yes
what is SceneManagement
SceneManager <--
Level 1
And how does that call click
no such thing as SceneManagement exists, 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
SceneManager.LoadScene(1);
wellllll...
I don't know why you're showing me this
Where are you calling click
I don`t understand
Debug the method.. see if it runs..
debug the SceneManager.LoadScene(1); see what it is
Where are you calling the click function
I just forgot do this
What is running click
Working now
i kinda figured out how to do it but i had a second question about the scoring system
Loading new scene
That's not what I asked but you seem to have fixed it anyway
Yes, thanks
what is the scoring system question?
what about scoring system?
just score++;
you can add 1 everytime u slice a fruit.
if fruits are worth different amounts.. u could do as navarone mentioned earlier.. and have a class called Fruit.. could store a public int fruitValue;
then when u hit the fruit u could access its fruit script and add that value to ur score instead.. score += fruitIjustSlashed.fruitValue;
ya perfect
overconvoluted af
only that?
lol
Maybe becouse of my bad english i can`t speak in 100%
still confused. Idk what to replace it with to load the lobby scene
have you bothered looking at the documentation what the proper class Is ?
how does one do that?
wild
ok
Usually by plugging in the thing you want to do into google and finding what shows up in the documentation
doesn't even have to be a good search. " how do i load a new level in unity " results in teh same link... just a few places down
How do I read local rotation.x of a transform in degrees between 360 and 0
localEulerAngles.x
That always results in some number that's 0 or very close to 0 randomly, not actually affected by the rotation of the object. (this object has no parent)
i need something that spits out the same value as the inspector transform component shows (it has some trickery that makes it nicely readable for humans).
Mathf.DeltaAngle(transform.localEulerAngles.x, 0)```
i've been punching my pc screen for like 6 hours on this
re: #๐ปโcode-beginner message no you're looking at rotation.x or localRotation.x
which is a quaternion thing
which is not euler angles at all
Ok so this seems to always have a result that's exactly -40 or very near -40. I'm going to assume at this point that something in my project is sersiously f*cked beyond repair and give up.
Thanks for the help.
Show your code
Debug.Log(Mathf.DeltaAngle(transform.localEulerAngles.x, 0));
What number are you expecting?
this still didnt work, i have another scene switcher script that works perfectly fine and the errors unity is giving me make absolutely no sense.
A number between 0 and 360 or -360 and 0, just something that actually changes in degrees.
What actual number though
whats the easiest way to figure out the vector2 for my raycasts direction?
How is your object rotated
starts at 0,0,0 rotation.
wdym still didnd't work
mate you had compile errors there is no way its gonna run
For example, I want it to go roughly 20 degrees ccw from -vector.up
You would be providing that vector2
-40 is between -360 and 0
I have no clue how I would go about making that calculation
Quaternion.Euler(0,0,-20) * Vector2.up```
that code spits out -40 and as the object is given angular momentum, it changes to some number like -40.0264837 and goes back to -40 as the object slows down. It never moves more than 0.1 in value away from -40 even if the x rotates 180 degrees
Ahh thank youu
how does it work for my other script. Im so confused. I used scenemanagement in it and it still worked
it's not your code that's the issue it's something in the project
show me
Show the inspector of the object you're doing this on? Maybe you have a component restricting the rotation?
You aren't using SceneManagement in this code
You dont see the difference ?
You're using the right one
lol just found you, whilst looking for how to get the normal of a raycast ๐
SceneManager.LoadScene
You're EVERYWHERE on unity forums
I'm all over the place
i edited it before hand and it still didnt work
what you sent before was a compile error. Fix your IDE first
That's correct now. Still not configured, but the code is at least correct. Are you getting any errors?
Actually little confused on this.
private SlopeCheck(){
RaycastHit2D slopecheck = VisualPhysics2D.Raycast(transform.position, Quaternion.Euler(0,0,-20) * Vector2.up, groundDistance * 1.2f, groundedLayer);
return slopecheck.normal;
Gives me an error on return saying its void and should therefore not have an expression after return, but... its not void is it?
Perhaps Im misunderstanding c# syntax
You haven't given it a return type
Look it up and see
but the errors are so random and they dont make any sense
hover the normal it tells you the type
See what RaycastHit2D.normal is
gotcha
What are the errors
they make sense, they usually tell you whats wrong
You have clear syntax issues
Vector2 it seems. thanks!
or you didn't save
Yeah, you need to configure your !ide so you can see all of your syntax mistakes
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
Also, what nav said I don't think you've saved your script
everyone just told me that doesn't work
No, we said SceneManagement.LoadScene didn't exist
The import is still needed
i replied wrong person sorry
but you've got other syntax errors
ok
and also you need to configure your IDE to see them
ok
So I've been trying to implement a knockback system to my 2d top down game. For testing purposes, I just added this code to my player movement script. However, when I press the key, the player does not move. Was wondering if anyone knew the solution to my problem!
Do you set velocity anywhere?
Do you have code elsewhere setting velocity to a fixed value?
ahhh yes i do
Then that overrides the force
You can either disable velocity setting for a time, use addforce for everything, or use adding to velocity with some kinda clamping
Probably other ways too that I can't think of
Cool cool! Tyvm! I will probably stick to just using velocity rather than add force since thats what most of my movement script is using!
better way to do this?cs IInteraction interaction = hit.collider.gameObject.GetComponentInParent<IInteraction>() ?? hit.collider.gameObject.GetComponentInChildren<IInteraction>();
the difference is GetComponentInParent and GetComponentInChildren
i want either that or the other
look through both
alright dont worry i got it
why do you have to check up or down the hierarchy? shouldn't it be the same layout for every GameObject with IInteraction?
but yes, you can change this to avoid using GetComponent to search children or the parent . . .
yeah thats what i realised
that the layout was the same anyways
i just got confused for a second
good. i was worried . . .
how comes this doesnt work?
they're named the same, put captilized I for prop
could also do public bool IsPlayerUnit => isPlayerUnit;
what doesnt work
navarone said to change the name of the property
not the name of the variable the property tries to return
this would also work completely fine
did you actually try it?
all good, should've been clearer my fault
i used this watever its called to expose isPlayerUnit to other scripts
but if i change the actual name
cuz there different
it dont work
acc sorry
if the public property is capitalized make sure thats the one you access from other scripts
idk how#
but apprenlty i haev
im trying to use it in this script
so i need to do the get thing
and what does the error say
the error is telling you why thas wrong
ok
ok theres nothing wrong with tthe link
but when i use that variable
in the same script
its an error
and it sasyy
please make a sentence at least before hitting send
send the full !code
