Moving a capsule with Blox by folllowing a C# script

(Paul GK) #1

As a follow on to my previous post I have been trying to get acquainted with Blox by following a C# player movement script I found on the net.

There is an error in the script on the right where the new Vector3 is, as it was originally set for a Vector2.

I have a character controller attached to my capsule gameobject and I have tried both with and without a rigidbody attached but it refuses to move.
Variables are set in Blox and showing below the attached Blox script in the capsules inspector.

I cannot seem to work out where I am going wrong?
Could someone please advise?
Thank you.

(Alien) #2

have you tried putting a debug in after the isGrounded?

i am having a heck of a time getting the isGrounded /if statement to work. but if you put all of your code above the If statement, it seems to move around. (the isgrounded trigger doesn’t seem to fire off).

(Leslie Young) #3

Performance tip: do not use GetComponent in Update. Put it in the Start event and save the result to the Blox Variable there. I guess you will get around to this and just wanted to get something working first; but I mention it just in case.

Like Alien suggested. Try adding Debug Blocks to your Event to see what is going on .For example; check if “isGrounded” is ever true since it can prevent the IF’s child Blocks from running if it n ever becomes true.

You should not add a RigidBody to an objects which has a CharaterController. You use the one or the other.

Check if you have a collider on the object or child object(s) which might be touching the ground before the character controller and preventing the character from reaching and “touching” the ground - not sure if this could cause a problem.

Also have a look at this since the problem seems to be with isGrounded; as Alien suggested:

In plyGame I do not even make use of isGrounded (probably because it was not working as expected) and keeping track of grounded state myself. But I only use it to determine which animations should be playing and to check if the character can jump. So the movement controls can still be used even when “in the air”. Not that it matters since falling should be fast enough so it is not noticeable.

gravityVec.y -= gravity * Time.deltaTime;
if ((characterController.Move((moveDirection + gravityVec) * Time.deltaTime) & CollisionFlags.Below) != 0)
	wasGrounded = true;
	gravityVec =;
	wasGrounded = false;

(Paul GK) #4

Alien, thank you for giving the script a go, very much appreciated.
I have been doing the late shift at work so not had chance to play since, but will have another go during the week. I did pop a debug in, and as you say the problem seems to be coming from the isGrounded statement.

Leslie, thanks for the performance tip, definitely one to remember :slight_smile:
I did kind of know about not using a rigidbody with a character controller, and really only tried it out of desperation as I was getting a bit frustrated at not being able to get it work. Sometimes you try anything in the hope LOL

I did check the collider wasn’t touching the ground and I even adjusted it to above the ground in case the problem was stemming from that.

Handy to know about the isGrounded not working correctly. I will maybe look at an alternate way such as a bool to see if the player is in the air maybe, similar to your wasGrounded variable?

Thank you both very much for the info and pointers :slight_smile:

(Leslie Young) #5

Just do your input logic without the grounded check. It is not really that bad allowing the player to move while falling. Feels more game-like anyway; except of course if you are doing something with some really accurate animations and input response. But then you are probably better off getting something to handle that part, like Motion Controller.

Of course you do not want the player starting a jump while not grounded. To achieve what I do with the custom wasGrounded would look something like this in Blox. I really should make some time to look into why grounded is not working. Probably something stupid.

Note the use of the BITWISE “and”, not the normal “and” operator. Maths > Bitwise > And.

(Paul GK) #6

Thanks leslie will have a play with your suggestions see how I get on :+1: :slight_smile: