Okay so I’m trying to code an OnTriggerEnter event for a “SlowingSludge” of sorts, so I have my own CharacterController script called “Character_Controls” and I have a plane with a sludge diffuse texture and a box collider attached thats set as a trigger but I dont know where to begin on referencing my walkspeed variable and lowering the float value from my controller when the player enters. (Feel free to use my controller code if you like) Thanks!!!
private var walkSpeed : float = 0.5;
private var gravity = 50.0; //New variable for code involving gravity
private var moveDirection : Vector3 = Vector3.zero;
private var charController : CharacterController;
private var strength = 0.5; //New variable for code involing objects the player collides with
//function that enables the keyboard cursors to transform the player direction + play associated annimations
function Start(){
charController = GetComponent(CharacterController);
}
function Update ()
{
if(charController.isGrounded == true) //using this code, the character animations should only play while the character is grounded
{
if(Input.GetAxis("Vertical") > .1)//input = upward cursor key or W key
{
walkSpeed = 0.6;
}
if(Input.GetAxis("Vertical") < -.1)//input = downward cursor key or S key
{
walkSpeed = 0.5;
}
transform.eulerAngles.y += Input.GetAxis("Horizontal");
moveDirection = Vector3(0,0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
}
moveDirection.y -= gravity * Time.deltaTime;
charController.Move(moveDirection*walkSpeed);
}
function OnControllerColliderHit (hit : ControllerColliderHit) //moves any game object with a rigidbody+collider component based on the strength variable
{
var body : Rigidbody = hit.collider.attachedRigidbody;
var pushDir = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);
body.velocity = pushDir*strength*10;
}