Hide trees when hiding the player
up vote
0
down vote
favorite
I have created a 3D game in unity with terrain and some models, where the player can go anywhere he wants and the camera follows him.
my problem is when the user is behind a tree, how do I make the tree transparent?
I have already done it to the other models with Ray casting but the trees are part of the terrain and therefore I get the terrain material and not the specific tree.
any ideas?
thanks in advance
c# unity3d tree raycasting unity3d-terrain
add a comment |
up vote
0
down vote
favorite
I have created a 3D game in unity with terrain and some models, where the player can go anywhere he wants and the camera follows him.
my problem is when the user is behind a tree, how do I make the tree transparent?
I have already done it to the other models with Ray casting but the trees are part of the terrain and therefore I get the terrain material and not the specific tree.
any ideas?
thanks in advance
c# unity3d tree raycasting unity3d-terrain
1
I think you identified your fix already:the trees are part of the terrain. That worked for you before but now you need them to be separate.
– Lews Therin
Nov 19 at 18:30
yeah but my terrain is big, so placing trees manually is not really an option… is there another solution?
– user9977758
Nov 19 at 18:35
Probably overkill but could you give the player's shader another pass that renders on top of everything (except for UI elements perhaps) slightly transparently?
– Ruzihm
Nov 19 at 18:38
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have created a 3D game in unity with terrain and some models, where the player can go anywhere he wants and the camera follows him.
my problem is when the user is behind a tree, how do I make the tree transparent?
I have already done it to the other models with Ray casting but the trees are part of the terrain and therefore I get the terrain material and not the specific tree.
any ideas?
thanks in advance
c# unity3d tree raycasting unity3d-terrain
I have created a 3D game in unity with terrain and some models, where the player can go anywhere he wants and the camera follows him.
my problem is when the user is behind a tree, how do I make the tree transparent?
I have already done it to the other models with Ray casting but the trees are part of the terrain and therefore I get the terrain material and not the specific tree.
any ideas?
thanks in advance
c# unity3d tree raycasting unity3d-terrain
c# unity3d tree raycasting unity3d-terrain
edited Nov 19 at 19:14
asked Nov 19 at 18:28
user9977758
7416
7416
1
I think you identified your fix already:the trees are part of the terrain. That worked for you before but now you need them to be separate.
– Lews Therin
Nov 19 at 18:30
yeah but my terrain is big, so placing trees manually is not really an option… is there another solution?
– user9977758
Nov 19 at 18:35
Probably overkill but could you give the player's shader another pass that renders on top of everything (except for UI elements perhaps) slightly transparently?
– Ruzihm
Nov 19 at 18:38
add a comment |
1
I think you identified your fix already:the trees are part of the terrain. That worked for you before but now you need them to be separate.
– Lews Therin
Nov 19 at 18:30
yeah but my terrain is big, so placing trees manually is not really an option… is there another solution?
– user9977758
Nov 19 at 18:35
Probably overkill but could you give the player's shader another pass that renders on top of everything (except for UI elements perhaps) slightly transparently?
– Ruzihm
Nov 19 at 18:38
1
1
I think you identified your fix already:
the trees are part of the terrain. That worked for you before but now you need them to be separate.– Lews Therin
Nov 19 at 18:30
I think you identified your fix already:
the trees are part of the terrain. That worked for you before but now you need them to be separate.– Lews Therin
Nov 19 at 18:30
yeah but my terrain is big, so placing trees manually is not really an option… is there another solution?
– user9977758
Nov 19 at 18:35
yeah but my terrain is big, so placing trees manually is not really an option… is there another solution?
– user9977758
Nov 19 at 18:35
Probably overkill but could you give the player's shader another pass that renders on top of everything (except for UI elements perhaps) slightly transparently?
– Ruzihm
Nov 19 at 18:38
Probably overkill but could you give the player's shader another pass that renders on top of everything (except for UI elements perhaps) slightly transparently?
– Ruzihm
Nov 19 at 18:38
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Well the best solution would be to start a Ray from camera to forward, and then put the camera a bit farther than the collision point, so that you can't see the tree.
Ray ray = new Ray(oldCam.position, oldCam.forward);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 5)){
cam.position = hit.point + oldCam.forward;
} else
cam.position = oldCam.position;
Remember to put the old camera position from where should be in order that the camera doesn't go away and stays there, and that the camera and old camera has the same code of position and rotation before this happens and then you just change their position. I mean I don't know if it's okay but you can take conclusions from this.
Sorry for mistakes I'm from Spain.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380621%2fhide-trees-when-hiding-the-player%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Well the best solution would be to start a Ray from camera to forward, and then put the camera a bit farther than the collision point, so that you can't see the tree.
Ray ray = new Ray(oldCam.position, oldCam.forward);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 5)){
cam.position = hit.point + oldCam.forward;
} else
cam.position = oldCam.position;
Remember to put the old camera position from where should be in order that the camera doesn't go away and stays there, and that the camera and old camera has the same code of position and rotation before this happens and then you just change their position. I mean I don't know if it's okay but you can take conclusions from this.
Sorry for mistakes I'm from Spain.
add a comment |
up vote
0
down vote
Well the best solution would be to start a Ray from camera to forward, and then put the camera a bit farther than the collision point, so that you can't see the tree.
Ray ray = new Ray(oldCam.position, oldCam.forward);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 5)){
cam.position = hit.point + oldCam.forward;
} else
cam.position = oldCam.position;
Remember to put the old camera position from where should be in order that the camera doesn't go away and stays there, and that the camera and old camera has the same code of position and rotation before this happens and then you just change their position. I mean I don't know if it's okay but you can take conclusions from this.
Sorry for mistakes I'm from Spain.
add a comment |
up vote
0
down vote
up vote
0
down vote
Well the best solution would be to start a Ray from camera to forward, and then put the camera a bit farther than the collision point, so that you can't see the tree.
Ray ray = new Ray(oldCam.position, oldCam.forward);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 5)){
cam.position = hit.point + oldCam.forward;
} else
cam.position = oldCam.position;
Remember to put the old camera position from where should be in order that the camera doesn't go away and stays there, and that the camera and old camera has the same code of position and rotation before this happens and then you just change their position. I mean I don't know if it's okay but you can take conclusions from this.
Sorry for mistakes I'm from Spain.
Well the best solution would be to start a Ray from camera to forward, and then put the camera a bit farther than the collision point, so that you can't see the tree.
Ray ray = new Ray(oldCam.position, oldCam.forward);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 5)){
cam.position = hit.point + oldCam.forward;
} else
cam.position = oldCam.position;
Remember to put the old camera position from where should be in order that the camera doesn't go away and stays there, and that the camera and old camera has the same code of position and rotation before this happens and then you just change their position. I mean I don't know if it's okay but you can take conclusions from this.
Sorry for mistakes I'm from Spain.
answered Nov 19 at 19:29
GuillemVS
11
11
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380621%2fhide-trees-when-hiding-the-player%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I think you identified your fix already:
the trees are part of the terrain. That worked for you before but now you need them to be separate.– Lews Therin
Nov 19 at 18:30
yeah but my terrain is big, so placing trees manually is not really an option… is there another solution?
– user9977758
Nov 19 at 18:35
Probably overkill but could you give the player's shader another pass that renders on top of everything (except for UI elements perhaps) slightly transparently?
– Ruzihm
Nov 19 at 18:38