- Home /
This question was
closed Oct 02, 2017 at 06:31 AM by
muhammadtahiriqbal for the following reason:
The question is answered, right answer was accepted
Question by
muhammadtahiriqbal · Sep 28, 2017 at 10:09 AM ·
c#positioncontrollerquaternionball
Move ball inside pipe like tunel
i want to ball move inside pipe like hollow cylinder.Ball constantly moving forward and by arrows we can move ball 180 degree left or in curved path right like
picture.i write that can move ball in curved shape but i can't able to move forward constantly.help me
currentRotation += Input.GetAxis("Horizontal")*Time.deltaTime*200;
currentRotation=Mathf.Clamp (currentRotation, -180, 0);
rotation.eulerAngles = new Vector3(0,0, currentRotation);
print (rotation * radius);
transform.position = rotation*radius ;

question.png
(12.9 kB)
screen-shot-2017-09-28-at-25348-pm.png
(97.2 kB)
Comment
Answer by Bilelmnasser · Sep 29, 2017 at 09:04 AM
hi, can be done with Rigidbody.AddForce like this :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class moveball : MonoBehaviour {
public float speed=2.0f;
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis( "Horizontal" );
float moveVertical = Input.GetAxis( "Vertical" );
Vector3 movement = new Vector3( moveHorizontal , 0.0f , moveVertical );
GetComponent<Rigidbody>().AddForce( movement * speed * Time.deltaTime );
}
}
Follow this Question
Related Questions
Camera Follow Player using a path 0 Answers
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer