I cant move rigidbody

Hello!

I have a problem when I try to synchronize a certain movement with a blender animation, for example, to jump, I can't do it.

And trying simpler things, without synchronizing the movement with the animation, everything I do, trying to use addforce or addrelativeforce, for example, pressing space to jump, without more, does not cause any kind of displacement in my rigidbody.

I don't know where the problem is, or if I'm doing it wrong. In principle, the code is that simple, to make it jump, right?

6845225--796991--1.jpg

You might've marked your Rigidbody as kinematic, which means it's not affected by physics forces. https://docs.unity3d.com/ScriptReference/Rigidbody-isKinematic.html

1 Like

There are probably a lot of ways of doing this. I have made two short visual scripts below (In Unity 2021.1.0b6) to display it. I like to use velocity change instead of add force. Also added a quick and dirty check if player is grounded before jumping, and also to make sure that the animation is idle when grounded, and jumping if jump. The animation is updating the boolean variable on the transition in animation. I just made a boolean called "Jump":
6846605--797243--upload_2021-2-17_13-32-32.png

And for the Animation to Work:
6846605--797249--upload_2021-2-17_13-33-13.png

And the animation controller to illustrate:
6846605--797252--upload_2021-2-17_13-35-24.png

Hope this can help :-)

Happy gamedev!

2 Likes

I have created both scripts, and even that I checked that the kinematic option is not checked, and it still does not work, there is no way for the Rigidbody to move, I do not know where the problem is.

Something to check:

Did you change from impulse to velocity mode in the add force ?

The mass in the rigidbody, is that a large number? or only one?

Have you tried to put in a large number in Y-axis (Add Force) ?

Are your coordinates X and Z in the plane, and Y upwards ? (Sometimes, Z-is used upwards.)

Have you added a "Character controller" ? That does not work any good with Rigidbody.

1 Like

Lets try a very simple jump then, with simple graphics.
For the visual script over, I changed the movement to Rigidbody.Set Velocity. And the recast distance to 1.

The Ground is a cube 10x0.5x10 as the screen below (with the jump script): 6847325--797366--upload_2021-2-17_16-42-19.png

The Cube in the screen has these properties:
6847325--797369--upload_2021-2-17_16-44-15.png

This should work for you ??

If using Bolt (And not the newest Unity Visual), you need to replace "If" with "Branch".

1 Like

Thank you very much for the inconvenience man!

But it still doesn't work, let me explain:

With the cube, it works perfectly, I follow your steps and there is no problem.

But I have tried it with another pj, different from the first one, and I have managed to make it jump, but deactivating the animator and nav mesh agent, with these two active, it doesn't work either, so it doesn't work either.

Finally I have tried again with the first pj, and it does not work in any way. Yes, this pj has animator too, and character controller, but if I deactivate both, the pj sneaks into the field, and the code doesn't work either, the "branch" always throws me negative.
(both pj, have the same mass as the cube)

In addition to this, now I have another question, if this gives problems with the character controller, which obviously I need to control the pj, how can I do all this, whether it jumps or moves forward in an attack animation for example, without the character controller? or how is it compatible with it?

Okay. Last attempt today :-)

I have updated the box with Character controller, and removed Rigidbody (Rather make gravity myself).

The player setup is like this:
6848873--797645--upload_2021-2-17_23-57-30.jpg
As you can see. No Rigidbody, only player controller.

Then, the scripts...

One movement script and one jump script. I have made some comments in the script grouping. The scripts are in the same graph:

Graph Variables. I have added three variables. One for walking speed, one for jumping speed, and one for gravity:
6848873--797648--upload_2021-2-18_0-1-10.png

Walk script: I get axis and create vector3 movement. Multiply with movement speed for Z- and X- direction. For the Z- direction, I have added gravity. Finally I multiply the final vector3 with Time.DeltaTime so it comply with frame rate.
6848873--797651--upload_2021-2-18_0-4-3.png

For the jumping, I use the character controller and check if it is grounded. If so, and the spacebar is pressed, I get the current velocity (If player is moving when try to jump) and extract the Z- and X- axis out and add jumpSpeed to the Y- axis. Then create a Vector3 and multiply it with delta.Time before putting into Character move:
6848873--797654--upload_2021-2-18_0-7-13.png

If this work, then you can add motion into the animation controller for movement. The animation controller is a state machine, so it can handle most of what you need :-)

1 Like

Just had to create a terrain with the cube and the logic :-)

Made a short movie of the result:

https://www.youtube.com/watch?v=6kkcdIpcQss

1 Like

Oh man! what a job! Thank you!

Yeah, this finally produces movement in my pj, I have eliminated the rigidboy, but, it does not work well at all, I explain:

Yes, the pj jumps like the video cube with these scripts that you have taught me. But first, to jump a little bit, I need to set the jumpspeed to almost 80, and it jumps right up. When I hit the space, it jumps suddenly, Fall, it falls well, it falls slowly like the cube, but it jumps super fast, more than a jump, it seems an instantaneous change of position ...:(

I've been testing things, and I've gotten the pj to jump, like the cube.

But I had to disable the animator's apply root motion (this is correct? Right?) This way if it works correctly as the cube at last. Although the grounded branch always gives me negative, and I have had to remove it.

I have tried to implement this with my pj's movement system (which rotates and moves with the corresponding animations) but I can't make it jump as with your system, no matter how much I try to copy and adapt it to mine. I show you my movement system, to see what you think.

Another question I have is that with this system (the system of the cube) it only works if I jump, but, if I wanted that when pressing the space, it was propelled forward? Because if I change the vector "y" of the jump, for the "x" or the "z", it does not move the same as in the jump.

Sorry if my doubts are a little obvious, I am new to using bolt and programming

I am currently not at PC tonight, but two things;

  1. If you try to use the check if grounded logic with the raycast option, it uses a max distance. And if you have a large character and for some reason the raycast starts from center of the character, the ray will never hit any collider at the ground if distance is not large enough. So you have to check that.

  2. Your logic looks like it will try to play two the animation in both direction at the same time. It also have some strange connections at the end. I can try to ahow you tomorrow if you dont figure it out. Try to get it working in one direction first.

Yes, my fault, I have checked it this afternoon, and I have been able to fix it, there is no problem with that.

Yes, there are two animations, it is actually the same, the running animation, but this way I get the animation to work from left to right, from top to bottom, and even diagonally. If I don't do it like that, even if the character moves in all directions, the animation only works if it goes from left to right, or from right or left, that is, horizontally, in all vertical movements, the animation does not work. It works at the same time with another turning system, so that the character can turn on himself.

I'm trying to spin my system with what I see in yours, even in one direction, it doesn't work ...:(:face_with_spiral_eyes:

1 Like

I am not very skillful when it comes to handle animation, but is your character/player a Rig? Meaning that it is a collection of arms/legs/head?

I can download an asset and try out some movement with a character rig.

I ususally use boolean values for move, jump, attack, idle.

Is it sword/axe or guns your character carries?

Are you moving in an open map? In all directions?

Are the camera following from behind or is it static in one direction?

[quote=“Sanctu”, post:10, topic: 829127]
this finally produces movement in my pj, I have eliminated the rigidboy
[/quote]I am not sure what this means but I certainly find it remarkable.

[quote=“hippocoder”, post:15, topic: 829127]
I am not sure what this means but I certainly find it remarkable.
[/quote]
I meant, rigidbody, sorry. because @Haneferd , he told me that for these movements that I want to do, that it is better to do it with the character controller than with the rigidbody,

Yes, exactly, it is a rig, with arms, legs ...

I used a mixamo pj, (xbot) and one of their running animations to test all of this.

No, he has no weapons or sword.

Yes, it is an open map, and it moves in all directions with wasd. And I have put the camera, as in Diablo III.

I have downloaded a free character rig from asset store, but I must admit that it is quite difficult to get it all playing properly. So, I need to investigate a bit further. Musch easier with only a cube :-)

Yes!! There is the problem, that making everything work with the animations and the movement together, is where I get lost XD I wish it were as easy as with the cube. XD

Answer-Part-1

I think I got the Movement thing going here. But, when investigating the Animation-rigs, it seems that you can decide to use the animation for jumping. The Animator - Update setting, can be set to "Update Mode: Animate Physics" . Not sure what that will do, but that is probably for some other forum-post.

Anyways. Here is what I achieved. Jumping and moving.

I downloaded a free Asset:
https://assetstore.unity.com/packages/3d/characters/low-poly-toon-adventurer-male-78374

I used the Prefab and changed almost all settings in CharacterController (Which I added), so it touched the ground. I removed the C# script, so I could make it in the Visual Script (Added a Graph). Also kept the Animator - Demo Controller. The result:
6859547--799697--upload_2021-2-20_21-28-9.png

Then I created a Terrain, and added some trees and cubes.

The Video shows the result:


So, for the Visual Scripting Logic.

I created a sequence of steps in the Update (I'll detail it below)
6859547--799706--upload_2021-2-20_21-39-35.png
Also created some graph variables to steer the walking speed, jumpHeight, gravity and playerVelocity. Also made a boolean isGrounded, as this is a problem to get right:
6859547--799703--upload_2021-2-20_21-38-17.png

For the update

sequence-0 (It is the ground check)

It gets the position of the player, then recast downward (Direction 0,-1,0 = Downwards in the Y-axis). The Max Distance must be larger than half of the player (It depends where the origin point of the player is.. Maybe check and try out)
Remember to change the Layer Mask on the terrain to Ground!

6859547--799712--upload_2021-2-20_21-41-37.png

1 Like