x


Crouching and falling through floor

Hello,

I am using the CharacterMotor.js and FPSInputController.js (basics) as movement scripts.

I created a basic game and just want the character to crouch now.

From reading various posts this is the script I created.

function Update ()
 {

   if (Input.GetKeyDown ("c"))
   {
      transform.position.y -= 0.5;

      transform.localScale.y = 0.25;

}

   if (Input.GetKeyUp ("c"))
{

      transform.position.y += .7;

      transform.localScale.y = 2.0;
}
}

My character starts a scale y = 2 (though 3 would be better)

I need to know how to make it so after hitting the "c" button to return to normal size (2/3) I do not fall through the floor. What do I need to fix?

more ▼

asked Sep 03 '12 at 02:35 AM

BluEye gravatar image

BluEye
11 2 6 10

FWIW ... is your floor very flat or is it hilly ?

Sep 03 '12 at 05:55 AM Fattie

It is completely flat.

I messed around with the controls a bit more and if I scale the character to Y=1 it is fine because after I release "c" (from it crouching) there really is no true crouch.

In other words while yes the character is crouching down to .25 for it to go back to 1.0 it is fine.

When it exceeds the 1.0 is when it falls through the floor because it is trying to 'grow' up and down at the same time.

If that all makes sense.

Sep 03 '12 at 06:09 AM BluEye

ok so you've completely fixed the problem.

DON'T use "-=" and "+=" ...

actually just SET the values. so, set them to 1, 0.5 or whatever you want.

Sep 03 '12 at 06:18 AM Fattie

I did not fix the problem because I need the character to actually resume the height of 2 or 3. I was just testing it out.

If I remove the "+ or -" the character will immediately fall through the floor.

Sep 03 '12 at 06:23 AM BluEye

OK let me explain. Firstly as I say do not use the "+=" or "-=" format. Just set them using "="

then of course, you must set the values CORRECTLY.

only YOU can figure out what they should be as you have the scene in front of you.

IF IT IS FALLING THROUGH THE FLOOR, MAKE THE "POSITION" HIGHER.

so if you try position.y = 3, and it falls through the floor, next you should try "4"

And so on

OK ?

Good luck

Sep 03 '12 at 06:31 AM Fattie
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x342
x97
x40
x39
x32

asked: Sep 03 '12 at 02:35 AM

Seen: 359 times

Last Updated: Sep 03 '12 at 07:46 AM