- Home /
Error when trying to implement JumpPad/GravityPad type effect on CharacterController (Solved)
I'm trying to create a jumpPad/launchPad effect in my game. Nothing fancy, just a simple boost upwards when the player runs across the pad.
After searching round the forums I came across this script, which seemed to be exactly what I was looking for -
#pragma strict
var moveVelocity : Vector3 = Vector3.zero;
private var thePlayerMotor : CharacterMotor;
function Start()
{
thePlayerMotor = GetComponent(CharacterMotor);
}
function OnTriggerEnter(ThePad : Collider)
{
if (ThePad.gameObject.tag == "JumpPad")
{
moveVelocity = Vector3(0,50,0);
thePlayerMotor.SetVelocity(moveVelocity);
}
}
But I get this error when the pad/trigger is activated -
SendMessage OnExternalVelocity has no receiver! UnityEngine.Component:SendMessage(String) CharacterMotor:SetVelocity(Vector3) (at Assets/Standard Assets/Character Controllers/Sources/Scripts/CharacterMotor.js:582) JumpPadLaunch:OnTriggerEnter(Collider) (at Assets/JumpPadLaunch.js:20)
Any help would be appreciated
???
Answer by gkepets · Feb 22, 2015 at 10:19 PM
i used this script:
#pragma strict
var strength : int = 10;
var jumppadsound : AudioClip;
// make sure to check the Is Trigger checkbox in the Box/mesh/whatever collider
function OnTriggerEnter(col : Collider){
// Make sure the "Player" tag is set on the player
if(col.CompareTag("Player")){
col.gameObject.GetComponent(CharacterMotor).SetVelocity(Vector3.up * strength);
audio.PlayOneShot(jumppadsound);
}
}
@script RequireComponent(AudioSource);
make sure the character is tagged "Player"
No good I'm afraid. I've assumed you meant swap the script from the Player Controller to the JumpPad object. I tried your script on the jump pad and the player/controller but got the same error message both times-
Send$$anonymous$$essage OnExternalVelocity has no receiver! UnityEngine.Component:Send$$anonymous$$essage(String) Character$$anonymous$$otor:SetVelocity(Vector3) (at Assets/Standard Assets/Character Controllers/Sources/Scripts/Character$$anonymous$$otor.js:582) JumpPadLaunch:OnTriggerEnter(Collider) (at Assets/JumpPadLaunch.js:13)
code from Character$$anonymous$$otor script thet the error refers to -
function SetVelocity (velocity : Vector3)
{
grounded = false;
movement.velocity = velocity;
movement.frameVelocity = Vector3.zero;
Send$$anonymous$$essage("OnExternalVelocity"); //THIS LINE ! ! !
}
???
Are you using the Unity FPS Controller ? If so, did you change anything on the Character$$anonymous$$otor script ?
If I go to the part of the script the error refers to and comment out that particular line -
function SetVelocity (velocity : Vector3)
{
grounded = false;
movement.velocity = velocity;
5. movement.frameVelocity = Vector3.zero;
//Send$$anonymous$$essage("OnExternalVelocity"); //THIS LINE NOW CO$$anonymous$$$$anonymous$$ENTED OUT ! ! !
}
It now works perfectly. However (throwing this question out to anybody who may know)
Is commenting out this line going to have an adverse effect on anything else? I've played through my various scenes and it doesn't seem to be affecting anything. So... am I going to be ok without this line of code (what exactly did it do anyway?)
???
I used the standard First person controller, and i dont know much about the fps controller.
O$$anonymous$$ thanks. Like I said it all seems to be working fine, just waiting to see if commenting out that single line of code throws up any issues later on.