I started to learn about Unity, and I have a problem with the Raycasting. So I have this code
if(Physics.Raycast(cam.position,cam.forward,out hit,100f,layer)){
Debug.Log(hit.point);
if(hit.transform!=this.transform){
showPreview(hit);
print(hit.transform.name);
}
}
and it works fine with objects and anything else, except the terrain. If the terrain is Flat, the raycast doesn't detect it, but if I make some mountains it works fine. Flat terrain, zero log / Tiny hill, it detects I tried to change the distance, but it didn't work.
I found the problem. In the script i used the fps character as camera, and it didn't detect the vertical rotation :D Thanks for the help!
Related
I try to do a 3d android game in Unity with c#. I put random barriers and code is works well. But problem is the barriers rotate comes wrong, I want to see from the front but they are coming from the side. How can I rotate them front? And how to fix overlap two barriers?
I've set up this enemy to turn into a ragdoll upon death, fly into the air a bit, and behave like a ragdoll. It is all working fine as far as i can tell.
Except i am encountering an issue where the enemy keeps popping in and out of existence, depending on the cameras rotation/position.
Here is what it looks like before the issue.
Then, from this position, if i rotate the camera slightly, it results in this:
The game is paused while this is happening so it is not related to movement in any way. I can also rotate the camera back and forth, and the model will continue to pop in and out of existence. No gameobject is being destroyed.
It it also nothing to do with the model clipping into / under the floor, as you can see in the pictures, i raised it up off the floor to test it, and it still happens while suspended in mid-air.
This issue only happens while the enemy is a ragdoll. If i turn off ragdoll deaths nothing like this ever happens.
Do you have any idea what could be causing something like this?
I am guessing that your enemy is using the skinned mesh render component. When using ragdolls and skinned mesh renders together the bones or vertices of the rig might get pushed out of bounds. Unity only renders your mesh if the bounds of it are in the camera view. The unity docs recommend either increasing the bounds or turning on "Update When Offscreen" on all of your skinned mesh renderers.
More info here
I would like to try and make a game similar to Altos Adventure. I am having trouble starting.
How to set up the terrain so that my character doesnt get stuck?
I simply drew a test sprite for the ground in photoshop. What collider2d should I use?
I use polygon collider and reduce friction in the material. But the character gets stuck, hits small invisible bumbs and it feels awful. The worst part is connecting 2 ground sprites together! The point where they connect is always messy.
I have a question for the future as well. How would I add the endless part of the game?
Would having many "pieces" set up and just spawning them as the player rides down work?
I havent written any code yet as the problem is simply in the physics in my opinion.
Thanks to anyone who takes the time and tries to help!
To move your player use rigid body.AddForce(Vector3 direction, ForceMode forceMode); then create a Physics Material with friction = 0 and put it in your player's collider.
Instead walking on the ground he walk through it same for the ship and debris the other objects. He stay on the ground on the terrain but all the other objects in the scene he walk through it.
In the past i added Mesh Collider to the ship sapceship and checked the Convex turned the Convex on so it worked fine. but now i tried to add Mesh Collider almost to everything in the scene and it didn't change anything.
The scene is not my own but there is nothing speical i think. A terrain camera and objects. I added the ThirdPersonController.
Maybe there is a way to solve it making a new script in c# ? So far i could not find solution.
Make sure the collider of the Player is big enought to hold the model. And also that the terrain collider is adjusted to the terrain.
Try to change Center(Y) value of CapsulCollider
Got a strange problem with unity3d which turns my terrain whiter the closer i get to it. I have tried creating new projects with plain terrain and it is still the same.
See screenshots below. The closer i get the whiter the terrain turns.
The solution was to decrease the base map distance for the terrain.