- Home /
This question was
closed Oct 28, 2017 at 05:38 AM by
Code_Skunk for the following reason:
Answered the question on my own. No productive response given.
Question by
Code_Skunk · Oct 25, 2017 at 01:01 AM ·
c#scripting problemcollisioncharactercontrolleraddforce
OnCollisionEnter Sine Wave to Character
Hello, my project at this point closely resembles a simple roller ball game. I am struggling with getting my roller ball to move in a sine wave function if collision with an game object is detected, here's my code.
public Text scoreText;
public Text winText;
public int Score;
private float moveSpeed = 5;
private bool useTorque = true;
private float m_MaxAngularVelocity = 25;
private float jumpPower = 2;
private const float groundCheckRay = 1f;
private Rigidbody playerRigidBody;
private float Speed, Width, Length, timeCounter;
private void Start()
{
timeCounter = 0;
playerRigidBody = GetComponent<Rigidbody>();
Score = 0;
textChanger();
winText.text = "";
GetComponent<Rigidbody>().maxAngularVelocity = m_MaxAngularVelocity;
}
void OnTriggerEnter(Collider Other)
{
if (Other.gameObject.CompareTag("Collectable"))
{
Other.gameObject.SetActive(false);
Score = Score + 1;
textChanger();
}
else if (Other.gameObject.CompareTag("MapVortex"))
{
playerRigidBody.AddForceAtPosition(swerlMove(), new Vector3(0,0,0));
}
}
Vector3 swerlMove()
{
Speed = 2;
Width = 5;
Length = 5;
timeCounter += Time.deltaTime * Speed;
float x = Mathf.Cos(Width * timeCounter);
float y = 0.5f;
float z = Mathf.Sin(Length * timeCounter);
Vector3 swerlRules = new Vector3(x, y, z);
return swerlRules;
}
Comment
Follow this Question
Related Questions
Any way to ignore collision between rigidbodies and colliders/character controllers? 1 Answer
Goal Collision for pong game 0 Answers
Collider not continuing to Ignore CharacterController after center changes. 0 Answers
Stop Root Motion if out of boundaries? Simple Wall Climbing System 1 Answer
OnCollisionEnter not working 1 Answer