Script for Character to be Pushed ?

I’m working on a level for my intro to level design class and I am trying to get the Dragon in the middle that is moving around to knock the player off the platforms when the player comes into contact. I have a script on the dragon and the Player is the rigidbody that gets knocked back but it happens only once or never. I’m not sure whats happening and I am very new to scripting and I have just been bouncing around the forums trying to figure it out.

All I need is a script that will allow me to have this action take place

If player is hit by the Dragon (the dragon is an animated object trashing around, not an AI) then the player will get knocked back.

I need this to happen every time and not just once. I have the respawn set up and everything else I need for the level. I just need this Dragon to collide and knock the player back. This is a platform style 3d level where the player is jumping from rock to rock trying not to get knocked off by the dragon and reach the end. I figured it would work the same as a swinging pendulum but I tried that and it doesn’t collide with the player. I need help and the project is due Friday. Any help is greatly appreciated and thank you for reading this.

-Cstop

Can you maybe post your script or part of it?
Without we can’t really see what’s going wrong.

  • var mass:float=3.0;// the lower the mass, the higher the impact
  • var hitForce:float=2.5;// impact “force” when hit by rigidbody
  • privatevar impact =Vector3.zero;// character momentum
  • privatevar character:CharacterController;
  • functionStart(){
  • character =GetComponent(CharacterController);
  • }
  • functionAddImpact(force:Vector3){
  • var dir = force.normalized;
  • dir.y =0.5;// add some velocity upwards - it’s cooler this way
  • impact += dir.normalized * force.magnitude / mass;
  • }
  • functionUpdate(){
  • if(impact.magnitude >0.2){// if momentum > 0.2…
  • character.Move(impact *Time.deltaTime);// move character
  • }
  • // impact vanishes to zero over time
  • impact =Vector3.Lerp(impact,Vector3.zero,5*Time.deltaTime);
  • }
  • functionOnCollisionEnter(col:Collision){// collision adds impact
  • AddImpact(col.relativeVelocity * hitForce);
  • }
  • @scriptRequireComponent(CharacterController)