can someone help me with the code?
I want my object to focus on an enemy that is just near.
The red dot should represent the opponent and the arrow should focus on the opponent
I think I need to work with the quaternion but I don't know exactly how to proceed
Related
I want to add knockback to my entire player when it shoots, so it can impulse itself.
I'm new to making games, I don't know much about c# and I haven't found any tutorials for the thing I need
Difficult to know what you need help on here. But try to I'll answer the question.
When your player fires their gun, you would typically create a new object and apply a force to it for slow move projectiles or alternatively, you'll do a ray trace to see if the target is hit for laser beam style shots.
To make the player move, use AddForce on their Rigid Body to apply a force in the opposite direction. That direction is simply the negative direction of the projectile's direction (or the ray that was traced)
i could need some help with this problem:
I have a ball flying around in random directions. everytime he collides with something, he changes the direction.
i also have a player, for which i want to write a simple ai script.
the player should go to the point, where he could meet the ball.
i made a simple picture for this problem in paint so that it's better to understand:
What i have is the yellow arrow, thats the ball's direction that it's moving. what i need is the red arrow direction for the player, but i don't know how to do this?!
thanks for your help!!
I have a ground and a cube, both have rigidbody and colliders. My cube is situated upper than my ground. I did management by cube using keys(for example i press 'S' and my cube fall down on 1). The problem is than my cube touches ground and i press 'S' it extends through my ground. Who knows how to solve it?
well...a simple solution can be to set a min value on that axis for the cube.
for example, something like that:
if(Input.GetButton("S")) //move object when u press S
{
//in this way your cube can move only if it's over the ground
if(cube.y > ground_y)
//your code to translate the cube
}
so if your colliders fail for some reason you have an additional check.
How can I make a gameObject rotate while jumping "in the air", then once it collides with another gameObject, return smoothly to its original rotation like shown in the following video: https://youtu.be/iOV0Apuwj94
I do not want the cube to abruptly return to its original rotation once it has collided with something. Like in the video, the cube's rotation is just right when it collides (when it hits the ground, it feels natural). I also want the cube to know where the future collision is, so that it can modify speed, rotation etc. depending on the positions of each gameObject (this way, the rotation would be always correct too).
I have tried many times fine tuning the rotation, but I always fail to get it just right (+predicting future collisions is unknown to me). I do not have the experience to accomplish such a task and searching the Web did not help either. I would appreciate any lines of code, guidance or help from the community. Thank you for your answers.
Here is a pseudocode I can think of which might work for you:
while(cube.y> 0)//or greater than the right value of y
{
if(cube.y= 0)//or the right value of y
{//stop performing rotation}
//perform rotation
}
This might just solve all your problems, since you are using a RigidBody for the cube which has a collider and it should automatically align to the ground due to gravity, in my opinion, making it feel even more natural.
This is the setup I have. I am trying to make a game in unity which appears 2d but is actually 3d. I have a simple sphere and a floor, which is made up of cubes placed next to each other(the colliders overlap a little) with the same Y value and Z value. My 2d plane is in X-Y plane(Z being the depth).
Now in the script attached to the sphere, in the Update function, I have used rigidbody.addForce() in the +ve X axis function to move the sphere forward. I have attached rigidbody to the sphere and enabled gravity. The collider of the sphere is the default one.
Now the problem is:
When I run this scene. The sphere moves forward but at the intersection of the colliders, it jumps a bit(very less but still noticable) upward and loses its momentum. It happens at every intersection.
BUT this does NOT happen if I place the sphere on a floor made up of a SINGLE cube(a very long one).
Is this problem arising because of overlapping colliders? How do I solve this issue?
Thanks in advance
I don't think this is fixable. Unity physics is approximate, and even when physics material are set up to 1.0 bounciness, momentum doesn't stay constant — I learned it the hard way when I tried to develop a game depending on constant momentum, and had to write my own little physics simulation for that.