- Home /
Script c+.How i throw player to any area.?
Hello guys i need help to do a script because i am modelator and i dont know a lot of scripts.i would like to create a script who i press any button i shoot a throwline and i go to this position or mesh .example batman shoot to walls he go to walls(gun).tHANKS sorry for my english.n.n
Answer by Josh707 · Oct 29, 2013 at 12:53 AM
Well what you're asking seems fairly simple, you could shoot a raycast from the camera with a max distance, and then just set the players position to the RaycastHit position if it hits something. So basically:
public Transform player;
public Transform camera;
private float shoot_distance = 5.0f;
RaycastHit hit;
if(Physics.Raycast(camera.position, camera.forward, out hit, shoot_distance)){
player.transform.position = hit.point;
}
else{
//Nothing hit, play a sound or something
}
player.position if you define player as a Transform. player.transform.position if you define player as a GameObject.
Oh yeah whoops, I wrote that kind of fast without thinking
Your answer
Follow this Question
Related Questions
How faster load texture from bytes? (Android) 0 Answers
Has anyone used MeshChartFree? 0 Answers
About Flare Effect - HELP - how to use 1 Answer