Unity 3D Character Controller using FSM & New Input System

Unity 3D Character Controller using FSM & New Input System

Jojik

2 года назад

31,837 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Tomas Skala
Tomas Skala - 06.11.2023 06:49

Greetings. I have a problem, I did everything according to the instructions, but it still gives me an error in the State script, with line 26 to 30 with actions, as if the script does not see the playerInput reference. I would be very happy if you could direct me or advise me. :D

Ответить
Fakhriyor Akhmedov
Fakhriyor Akhmedov - 09.10.2023 07:54

question: how to u exit crouching state?

Ответить
Cosmic Sparkles
Cosmic Sparkles - 17.09.2023 18:17

Mine is stuck in idle as well. No inputs working. Here's everything:
I changed the Start to Awake in Character script (as per suggestion in another comment below), that took away two errors (null handle input) but left me with:

ArgumentException: GetComponent requires that the requested component 'PlayerInput' derives from MonoBehaviour or Component or is an interface.
UnityEngine.Component.GetComponent[T] () (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/Component.bindings.cs:42)
Character.Awake () (at Assets/StateMachine/Character.cs:55)

My line 55 in Character script is
playerInput = GetComponent<PlayerInput>();

I don't get it, since the Character script (which this tutorial makes a Class and attaches to Player) IS monobehaviour. And the PlayerInput is autogenerated when you click the Action Map C# generate button, so that can't be changed--and I'm pretty sure that is an interface or Component.I made sure "Sprint" has press and release in its binding as well.

The ONLY thing I can think is I have another script for a keyboard action (press 1, this thing appears, press 1 again it disappears) using PlayerInput Action Map as well. Since there's no movement of the Player, or change to his movement state (other than clicking the object or pressing 1, which I don't think counts) I don't think that script should go in the FSM, or interfere with it? It has these lines:
PlayerInput Input;
(and then in Awake it has...)
Input = new PlayerInput();

Are those two combatting each other for PlayerInput() or something?

The other thing I ran into was it didn't recognize the word 'actions' in the State script lines like moveAction = character.playerInput.actions["Move"]; 

so I had to change those to moveAction = character.playerInput.Player.Move; Which got rid of the error but didn't help him actually move. Either way, I don't think this should cause the Argument Exception error above.

It's like none of the FSM/Character scripts are getting called from the Action Map (Player) actions which should start their respective movement from the animation tree (pretty sure I matched your tree exactly)? This is my fourth different tutorial series for character movement and I have gotten that "actions" error on all of them. Changing actions["Move"] to Player.Move has worked on the others. Sidenote: I got one state machine working from a tutorial (the Jump like Super Mario one), but it was doing a jump that was 3 different velocities depending on the jump (in a sub state machine in animator) and I just didn't like the way it was looking or feeling for my game. It called actions from context using the .ctx code.


Any thoughts, ideas, or help greatly appreciated!

Ответить
Francisco Barba
Francisco Barba - 11.09.2023 06:57

Hi, thanks for the tutorial it is really great, I jst can't make function the sprint juming, the animation plays but it stays on the same position, and I can't figure out what is wrong with, can you help please?

Ответить
Kamillion
Kamillion - 07.09.2023 07:16

Can anyone help? Everything is working correctly, scripts rechecked. But the character plays only Idle. If you manually move the slider in Locomotion Blend Tree, everything works.

Ответить
Мухаммад Гочияев
Мухаммад Гочияев - 28.08.2023 21:34

Bro my character is sliding on the map what could I do wrong?

Ответить
vis olo
vis olo - 21.08.2023 18:15

5;06

Ответить
TrilloBit3s Games
TrilloBit3s Games - 19.08.2023 19:51

Pra quem esta com erro no crouch é só criar uma Layer chamada Player na camada 8 e colocar ela no player, e la no script do CrouchingState voce pode usar int layerMask = 1 << 8;
Mas se preferir pode usar int layerMask = 1 << LayerMask.NameToLayer("Player"); //se usar essa comente a linha de cima e crie uma Layer Player onde desejar

Ответить
Lan Ha
Lan Ha - 13.08.2023 14:41

can you give me the project?

Ответить
HistoryVault
HistoryVault - 10.08.2023 02:31

What do I do for the look input in the input system?

Ответить
Hossam Al-Badry
Hossam Al-Badry - 07.08.2023 12:49

Can you send the source code of this project ??

Ответить
SaynedBread
SaynedBread - 02.08.2023 19:48

I'm new to game developement with Unity so I don't know much about it. But it appears that I don't know where I should place the rigidbody for the character.. and I don't know how to set up the animations like that, I just can't get it to work. Hopefully someone can help with that. I would really appriciate that.

Ответить
CBass Reds
CBass Reds - 30.07.2023 07:45

I don't know what I missed but when I press Start play in Unity, doesnt work and show me a message that is not working on the Console. The message is about something going wrong with Update() and the FixedUpdate() in the Character script.
If someone know what I do wrong, it would helps a lot.

Ответить
Mustafa
Mustafa - 10.07.2023 14:43

hello ı am amateur so it can be dumb question but ı want to ask we use to much update in this video and ı want make a big project. is this way comvinient for me or ı need to change anythink. thanks for great tutorial.

Ответить
Samuel l'etandrine
Samuel l'etandrine - 09.07.2023 02:23

please help me i am stuck and need this badly for my school project due in 4 weeks :( i follow the steps rewatched the video several times but when i run it he character stay in Idle state and even when i pressed the keys nothing happens

Ответить
Samuel l'etandrine
Samuel l'etandrine - 08.07.2023 21:21

i did everything the same but still character stay in idle state and when key is pressed nothing happen
can you help ??

Ответить
NotRandomPlayer
NotRandomPlayer - 06.07.2023 19:18

I got many issues with the code, for example, my animator dosent work, and it dosent allow me to use it as a avator do you have anyway how we could fix it

Ответить
Kutay Perk
Kutay Perk - 02.07.2023 15:32

Hello! I can't get out of crouch and i get this error 'State' does not contain a definition for 'toString' and no accessible extension method 'toString' accepting a first argument of type 'State' could be found

Ответить
Ritchz
Ritchz - 28.06.2023 06:33

Great vid!, i just got one issue, when i press jump while my character is sprinting it gets stuck(it looks like isn´t getting any speed value); i already watched the video a couple of times, but i cant find out whats wrong, any ideas?

Ответить
Sibel
Sibel - 08.06.2023 03:50

How do you make started, performed and cancelled phases work with state machines?

Ответить