How do you debug 3D raycasts? - c#

In Godot, if a 3D raycast isn't hitting where you'd expect it to hit, how do you debug it? I'm looking for some way to draw the ray (or a line that follows the ray), problem is, I can't find anything in the docs, so your help is much appreciated.

Sadly there is no easy way to accomplish a "Line3D" in Godot (There are some free assets and third party solutions for that).
However, being for debug purposes, all you have to do is enable "Visible Collision Shapes" on the "Debug" menu.
A common use of RayCast is to do them from the Camera. In which case they probably look like a point. And if you are also updating them every frame, they would follow the camera continuing to look like a point.
In that case, I suggest to duplicate or stop updating the RayCast you want to inspect on a key press. Said another way: Check if the user pressed a key, and when they do, either duplicate or stop updating the RayCast. Then you can move around and see the RayCast from an angle where it does not look like a point.

Related

How to make realistic shot in Unity

I'm just wondering how to make shots in my game more realistic. I mean there are two main ways in implementing shots. First: throw a small projectile and let it detect collisions. Second: use raycast. But in real world (and apparently I noticed this in PUBG) bullets fly really quick but not immediately. Here is why you should aim near your target if it's far away from you to hit it. Because if you aim right where it is it will move and your bullet will miss the target.
I'm just curious if any of you, guys have a nice solution to this problem. Also I wish to find a way to use raycast not every frame. In such things like detecting if you will actually hit the wall when shooting. If you have any good ideas how to implement spread and recoil for different types of weapons I will be happy to read them.
Blue point is bullet point of frame. and in very frame send a new raycast to check cross any human. like red line in this picture.
and bullet path use unity built-in Physics system to do it.

RTS Camera: The y and z values seem to be mixed up

I've been trying to figure out how to use the RTS plugin from the unity Asset Store but there seems to be a problem. I have no idea why this is happening, but the z and y values are mixed up. I can scroll left and right perfectly but whenever I press "W" the screen zooms out instead of moving upwards. The same applies to scrolling. When I scroll, the screen moves upwards/downwards and doesn't zoom out like its supposed too. I tried creating my own RTS camera via Brackeys and the same thing happened. His game would zoom, mine would just move upwards. I'm not for sure whats wrong. Im fairly new to all this unity jazz. ANY help would be appreciated
it's a little hard to know exactly why this is with the information you have provided. But if I were you the first thing I would check is your input manager! Have you done that and made sure your inputs correlate to exactly what you want?
It's sounds like your settings may be not be the default, causing the differences?

Unity Multiplayer Cube Auto Move?

I have followed the Unity official Multiplayer Guide below and everything works, except for the fact that when I run two instances on the same computer (1 in build run and the other in the play mode) the characters for some reason auto move in a circle.
I have no idea why this is since I have followed the tutorial exactly, unless I missed something :P I am currently on step 9 (identifying local player) and I stopped there cause my players keep moving in circles.
To Clarify, they aren't spinning in place, they are walking in a circle. Just imagine a person following a dotted circle on the floor, same idea.
This issue only happens when i run two instances (build run mode and play mode in unity). if i try only the play mode in unity, everything works fine.
Has anyone experienced this before?
Unity Multiplayer Tutorial: https://unity3d.com/learn/tutorials/topics/multiplayer-networking/network-manager?playlist=29690
I am on version 2017.2.0f3 <-- maybe this is why? should I update to a different patch?
Thank you in advance
Where I spawn the characters
build and run, player just moves in circles automatically
both build run and play mode, they both again moves in circles automatically
I see a first issue in your code:
PlayerController.cs line 36, you wrote
var bullet = (GameObject)Instantiate(BulletPrefab, BulletSpawn.transform.position, BulletSpawn.transform.rotation);
it should be
var bullet = (GameObject)Instantiate(BulletPrefab, BulletSpawn.position, BulletSpawn.rotation);
Since BulletSpawn is already a Transform. Otherwise bullets might not fire in the gun direction.
I don't have any of the player moving without me pressing keybord key.
Here is a screenshot of 2 build run working good:
I also tried Build run + Unity Editor in game mode, I had no problem.
Maybe the problem comes from your keyboard or the input manager of unity ? Since you are using Input.GetAxis, check this https://docs.unity3d.com/Manual/class-InputManager.html
The issue with your character automatically moving is because you have something plugged into your computer that acts as a controller/joytick. Go into settings for controls and set all joystick to the last joystick #. Make sure you set this for all vertical and horizontal movement. That should do the trick.
For example, if you use a 3D mouse like 3D connexion, it could act as a joystick/controller and auto move your character.

Unity3d detect the click on a plane

I'm trying to detect when the user click on a plane in C#. I tryed OnMouseDown() but it has no effect.
According to some topics on the web, the object must have a collider, but my plane has one.
I also found topics talking about raycast, but I must admit I don't really understand what it is and what it does. Could someone lead me to a good and (relatively) simple exemple that explains well how to do what I would like to do?
Thanks, have a good day
From my previous comment, the plane was marked as Trigger.
"This function is called on Colliders marked as Trigger if and only if Physics.queriesHitTriggers is true." from here.

Unity3D Changing Ball Direction When Hitting a Cube

I'm working on a simple Paddle Game project nowadays. In the begining, everything's looking good. But, when I complete my level design and publish my game, I see gameobjects in my scene are moving so slow. I think, I pass over the Unity3D's physics limit. If I try some Math instead of Unity3D's Colider, I can finish my first project. (I tried to use Separating Axis Theorem, but I can't handle x and y coordinates on Unity3D.)
I need your help. Thanks a lot for your time. (And If I can handle this problem, I will share my project on the internet, for beginner people like me.)
In my project, I achieved this simulation with using BoxColider, but because of Unity3D physics limit, I don't want to use colider in my project.
You can't not detect collision. I'd recommend using Unity's colliders for that, since they're really not bad. The first thing I notice is that in your first simulation, you have 4 box colliders, when instead you should just have one. Use the OnCollisionEnter event (on the spheres) to reflect them off your box.

Categories

Resources