- Home /
Player damage and knock backwards script
I am using the Lerpz tutorial as a base, so my character uses the same scripts and Lerpz, the fallout catcher works to kill the player which is great, but how would I go about setting it so that when the player collides with lava (solid plane) it takes away just 1 portion of health and knocks the player backwards and into the air a little, resulting in the lava causing a health chunk to disappear and the character to be thrown backwards and hopefully out of harms way. In an ideal world i would also have a slight amount of particle smoke appear at his feet but it's not as important.
Answer by Louard · Apr 07, 2012 at 06:06 PM
If you are using the Character Motor there's a function for that. After three days of trying to roll my own solution based on a few posts to the forum and the Answers I found this function and VOILA! Exactly what I wanted to do! Perfect for jump pads and knock back! Here's what my jump pad script now looks like.. MUCH simpler! The SetVelocity() function in the Character Motor accepts the velocity as an initial force and the motor takes care of the rest.
#pragma strict
var moveVelocity : Vector3 = Vector3.zero;
private var thePlayerMotor : CharacterMotor;
function Start(){
thePlayerMotor = GetComponent(CharacterMotor);
}
function OnTriggerEnter(WhatHitMe : Collider){
if (WhatHitMe.gameObject.tag == "JumpPad"){
moveVelocity = Vector3(0,50,0);
thePlayerMotor.SetVelocity(moveVelocity);
}
}
Your answer
Follow this Question
Related Questions
Don't destroy player after disconnecting or calling ClientScene.RemovePlayer() 1 Answer
Player Damage to enemy damage melee system 0 Answers
How to make triggers collide with player? 2 Answers
Player not getting destroyed when touched by enemies 4 Answers
Changing the Slider.value cause a lag problem in an Android device. 1 Answer