How to make object solid with Vector3.MoveTowards?
I have a sphere which moves to my mouse position when I click on the screen. I also have a cube, now I can move trough the cube, but I want the cube is solid so I can`t move trough it. This is my code:
public bool canMove = false;
public Vector3 endPoint;
public float duration = 50f;
void Update(){
if(Input.GetMouseButton(0)){
canMove = true;
endPoint = Input.mousePosition;
endPoint.z = transform.position.z = Camera.main.transform.position.z;
endPoint = Camera.main.ScreenToWorldPoint(endPoint);
}
if(transform.position == endPoint){
canMove = false;
}else if (canMove){
transform.position = Vector3.MoveTowards(transform.position, endPoint, duration * Time.deltaTime);
}
}
How can I make the cubes solid so I can`t move trough it?
Sorry for bad formulated question.
What's with all of the strang numbers in your code? Try pasting it after clicking the 010101 button.
I don't know why, but the code syntax is not working 9 of the 10 times
Answer by RLin · Sep 07, 2015 at 01:56 PM
Proud would probably have to add a rigid body and collides to make it so that the two are solid objects, and use addforce or set the rigid body velocity in order to mov the objects.
Thanks for your answer, but can you tell the code how I can move?
Your answer
Follow this Question
Related Questions
Movement Sticking 0 Answers
How to make more realistic bot AI? 2 Answers
Grabbing the Relative eulerAngles.y of a Rotation 1 Answer
MoveTowards resets position 1 Answer
Move a object along a vector 1 Answer