How do I go about shaking UI GameObject in Unity? As in, for it to go up and down and side to side.
I have UI Text GameObject that display points. When triggered, I want it to shake. I've tried using Vector 3 but I feel like I'm using it incorrectly. Some help or pointers would be appreciated.
Once again, it's an UI object that I want to shake on canvas.
Thanks!
You can do this a bunch of ways. Attach a script to the ui element. In the script update loop you can play with the gameObject.transform.position values. You could also use lerp to lerp back and forth to different destinations. You can do it in more ways as well but these would be the easiest to implement.
https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html
Related
I am trying to get a player pull and push objects in my 3D game. I am mainly focusing on pulling and pushing a box. Now when a player collides with a box and the E key is pressed the isKinematic of the box becomes false, and the player is able to move the box with its own mass.
I am trying to implement a basic pull and push interaction of the object. I have been thinking moving the box along with the movement of the player based on the WASD input but it doesn't sound stable, which road should I take here? Should I use a Fixed Joint connect them? I tried putting the fixed joint the box and making the connected body the player, but now the player is not able to move like there is a collision around it.
What is the best way to implement this? Should I use Fixed Joint or take a different way? Thanks.
if you really want to work with physics, i would say use a rigidbody. Use the rigidbody.AddForce or rigidbody.velocity to move your player. or use the transform by lerping to the position, but this is a bit messy and could not register all of the collisions if you are working on a fast object.
I am making a fps in unity and a game mechanic that I am trying to get is wall running/jumping
I have watched many tutorials but they cant fix the trouble I am having. To understand the code I need to explain the wall run. Basically what happens is that I have an empty game object
that raycast the left and the right of the player detecting for a wall. if it finds a wall and I'm holding left or right button (depending on what side the wall is on) it will add a force pushing the player towards the wall and another force pushing me forward. if I jump of the wall it will add a force depending on where I jumped. to make sure it was working I made a bool Value called iswallrunning but its never been set to true. can I get help with this
Code: https://github.com/ZeeScratcher/Project-robot-game/blob/main/WALLRUN.cs
Looking from the code:
you should only write code into the methods which they are responsible for. In StartWR() do not call StopWR(). This will be done in CheckForWR().
I don't know where Orientation comes from. I suppose this is from a child game object. This is fine, for a test replace Orientation by transform.
You can visualize the rays with Debug.DrawLine().
Better apply the physical force from the event FixedUpdate() instead of Update().
It is safer and more performant to cache with GetComponent() in the Awake or Start method instead of Update. If you are next to a wall in the first frame you will get a null pointer error otherwise.
Check if your walls match your given physical LayerMask and the walls have colliders.
If it is easier for you write all code into the Update() method and split it later into methods.
It would be nice to upvote my message, so I can finally make comments in Stackoverflow.
Kind Regards,
Chris
It's a 360 Video application on Unity 3D.
I want to place several objects around the camera (which has a fixed position), but I need this objects to have the same distance (same radius) from the Camera (which is the center). How can I do this? Either on Editor or by code.
I have been manually displacing objects around the camera, by dragging them by arrow tool. But it's as inaccurate as a pain to do. :)
Any light on this would help me a lot! Not only me, but anyone working with 360 videos in Unity.
Thank you all in advance!
To solve your problem, an easy solution would be to add a child "child_of_camera" to your camera and then add a child "child_of_child" to the "child_of_camera".
Now that you've done this, move the "child_of_child" away to however far from the camera you'd like it to be. After this, apply the random rotation you'd like to "child_of_camera".
Duplicate "child_of_camera" to however many objects you'd like on screen and then rotate them all to your preference.
Now, when you're moving around the camera, these children will follow along with the camera.
If you're looking so that the rotation of the camera doesn't affect the objects there are two ways you can handle this:
Place camera and "child_of_camera" (this name would now be misleading and should be renamed) under an empty GameObject and move "empty_GO" on the X,Y,Z axis instead of the camera.
or
Create a quick script to attach onto "child_of_camera" so that it always sets the "child_of_camera"s world space rotation to Vector3.zero.
As I stated in the comments, this solution is most likely not the optimal way to fix your problem but it is definitely a very simple solution that is easy to understand and implement. I hope it helps.
As far as I know, there are ways to manage Animation
Immediately,
Managing in the form of objects.
Managing with Sprite Images.
Is it effective to manage animations
in object format to manage character's joints in 2D animation?
What should I do to make it easier for me to understand Unity Animation?
As a beginner, we need a lot of data. I need your help. Help me.
I am going to explain the animation by manipulating GameObjects.
You need to add an Animator component to the GameObject you wish to animate. The animator component needs an animator controller. You also need to create an animation clip which represents an animation.(Animation controller is automatically created when you create an animation clip)
Now, to get started with animation you need to focus on animation clips. After you add an animation clip, you can record an animation into it. You do this by hitting the record button in the Animation window. While recording, any changes made to the GameObject will be recorded into the animation clip. (For example, you might move your GameObject). Any such change will create a key frame in the Animation timeline. The time point where key frame should be created can be changed.
Unity will interpolate the changes between two keyframes automatically.
However, there is also an animation curve which allows you to define how changes are applied between time points.
After you record animations you can define how transitions between different animations are made in the Animator Window.
unfortunably I am not really sure what your question is about?
For question this might be helpful:
https://www.youtube.com/watch?v=PuXUCX21jJU
Usually you have a Image File with the animation movements of your 2D Image object and using the "Sprite Editor" to cut them out for Unity.
You then add this Clip on a Animimation Component to be added to your "GameObject".
Since this is a "C#" question, maybe you want to know how to access this Compnent. The best is to use it in the "Init()" and add:
var anim = GetComponent();
Now you can use the "Animation" Component to play the configured Animation Clips.
I hope this helps you a little bit.
I am working on multiplayer collaboration in Unity3d using Smartfox Server2x.
But I wish to change it in to a hide and seek game.
When the hider (third person controller) presses the button "seek me" the seeker tries to find the hider. But I don't know How can I identify when a seeker sees the hider. Is it possible using Raycasting. If yes how? Please help me.
void Update () {
RaycastHit hit;
if(Physics.Raycast(transform.position,transform.forward,out hit,50))
{
if(hit.collider.gameObject.name=="Deccan Peninsula1")
{
Debug.Log("detect.................");
}
if(hit.collider.gameObject.tag =="Tree")
{
Debug.Log("detect.........cube........");
//Destroy(gameObject);
}
}
From Unity Answers by duck:
There's a whole slew of ways to achieve this, depending on the precise
functionality you need.
You can get events when an object is visible within a certain camera,
and when it enters or leaves, using these functions:
OnWillRenderObject, Renderer.isVisible,
Renderer.OnBecameVisible, and OnBecameInvisible
Or you can calculate whether an object's bounding box falls within the
camera's view frustum, using these two functions:
GeometryUtility.CalculateFrustumPlanes
GeometryUtility.TestPlanesAABB
If you've already determined that the object is within the camera's
view frustum, you could cast a ray from the camera to the object in
question, to see whether there are any objects blocking its view.
Physics.Raycast
You could do many things to find out if a seeker has found the hider. I am going to suggest how I would do it and I will try to make the idea/code as efficient as possible.
Each GameObject knows its position via the transform component. You can check how close one object is from the other by creating a ratio and comparing how close they are from each other. The moment both objects are close to each other then you enter a new state. In this state you will fire a RayCast only when the direction/angle of view of the seeker changes. So think of it this way, your seeker is looking around and as he is spinning he is firing the RayCast. The main idea is not to fire way too many RayCasts all the time which will hinder performance. Make sure your RayCast ignores everything except who you are looking for.
If you get stuck you can ask a more specific question, probably regarding RayCast and how to make them ignore walls or not shoot through walls, or maybe you discover that solution on your own.
Good luck!