- Home /
Question by
Klousianic · Apr 13, 2015 at 09:05 PM ·
c#movementtransformplayer
Need your help by movement
Hi everyone! I have an movement script and I need an rigidbody, but my script is not compatible with an rigidbody. SO what must I do, to make, that my script work with an rigidbody. using UnityEngine; using System.Collections;
public class Bounce : MonoBehaviour {
float lerpTime;
float currentLerpTime;
float perc = 2f;
Vector3 startPosition;
Vector3 endPosition;
void Update () {
if(Input.GetButtonDown("up") || Input.GetButtonDown("down") || Input.GetButtonDown("right") || Input.GetButtonDown("left")) {
if(perc == 2f) {
lerpTime = 2f;
currentLerpTime = 0;
}
}
startPosition = gameObject.transform.position;
if(Input.GetButtonDown("right") && gameObject.transform.position == endPosition) {
endPosition = new Vector3(transform.position.x + 2f, transform.position.y, transform.position.z);
}
if(Input.GetButtonDown("left") && gameObject.transform.position == endPosition) {
endPosition = new Vector3(transform.position.x - 2f, transform.position.y, transform.position.z);
}
if(Input.GetButtonDown("up") && gameObject.transform.position == endPosition) {
endPosition = new Vector3(transform.position.x, transform.position.y, transform.position.z + 2f);
}
if(Input.GetButtonDown("down") && gameObject.transform.position == endPosition) {
endPosition = new Vector3(transform.position.x, transform.position.y, transform.position.z - 2f);
}
currentLerpTime += Time.deltaTime * 5.5F;
perc = currentLerpTime / lerpTime;
gameObject.transform.position = Vector3.Lerp(startPosition, endPosition, perc);
}
}
Don't forget! I want, that my player moves on the x/y axes +1. Sorry for my bad english! Thank you!
Comment
Your answer
Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
Modifying the Transform of a GameObject 1 Answer
How do I check where my character is moving before he moves there? 1 Answer
Problem with player movements 1 Answer
3D Character Controller slowing down the higher the slope angle (both up and down) 1 Answer