x


when dashing, my character pass thru to any object

hi, i need help with my game, i got this problem when my character dash forward it pass thru to any objects with collider on it but when im not dashing and just walking around it works fine and im not passing thru to any object (hope u get what i mean with this, im not english guy). Here's my script

 var ctr = 0; var isDashing = false; private var dashDistance = 50; function Update() {  if(Input.GetButtonDown ("Dash"))  {  isDashing = true;  }  if(isDashing)  {  transform.Translate(Vector3.forward * Time.deltaTime * dashDistance);  ctr++;  }  if(ctr> 15)  {  isDashing = false;  ctr= 0;  } } 
more ▼

asked Jun 21 '11 at 12:14 AM

reignier gravatar image

reignier
1 1 1 3

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

If you're using CharacterController, then you should be using Move() or SimpleMove() to move, not translating the transform. You may need to increase the Skin Width of the controller too.

more ▼

answered Jun 21 '11 at 11:38 AM

Waz gravatar image

Waz
6.5k 23 33 71

ok ill try that, i think i saw that somewhere in script reference, tnx ^_^

Jun 21 '11 at 01:38 PM reignier
(comments are locked)
10|3000 characters needed characters left

i have solve the problem, this should be fine, tnx for the help warwick alison! this script also works perfectly with third person controller script or just create new javascript and attach this. ^_^


public var dashDistance : float = 25.0;
private var counter = 0;
private var isDashing = false;

function Update()
{
	var controller : CharacterController = GetComponent(CharacterController);

	if(Input.GetButtonDown ("Dash"))
	{
		isDashing = true;
	}
	if(isDashing){
		var forward : Vector3 = transform.TransformDirection(Vector3.forward);
		var curSpeed : float = 3 * dashDistance;
		controller.SimpleMove(forward * curSpeed);

		counter++;
	}
	if(counter > 15){
		isDashing = false;
		counter = 0;
	}
}

more ▼

answered Jun 21 '11 at 03:22 PM

reignier gravatar image

reignier
1 1 1 3

(comments are locked)
10|3000 characters needed characters left

It is because you force the Rigidbody to not take physics into account when you use Translate. If you want to add extra force in some direction try using AddForce() instead.

more ▼

answered Jun 21 '11 at 12:19 AM

save gravatar image

save
8.3k 22 31 63

i attach this with character controller, i cant add with rigidbody with it

Jun 21 '11 at 05:48 AM reignier

I see, have you considered making it a rigidbody instead? From my experience the movement is much better done with physics.

Otherwise I'm not sure if this might be suitable for you, but you could in the moment of "dashing" store the object in front of the player (or cast a ray in its forward direction) and check the distance, when the distance is to small you set the isDashing to false.

Jun 21 '11 at 10:44 AM save
(comments are locked)
10|3000 characters needed characters left
Your answer
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:

x516
x159
x2

asked: Jun 21 '11 at 12:14 AM

Seen: 816 times

Last Updated: Jun 21 '11 at 03:22 PM