I am using the oneShot Explosion_1 from this asset:
https://assetstore.unity.com/packages/vfx/particles/particle-effects-1-90769
I want to rotate it by 90° on the x-axis, but if i change the rotation of the object, or its parent object it has no effect on this particle system.
What i tried yet:
disabling velocity over lifetime
changing the simulation space to world
try to rotate the gameobject with the particle system
add the gameobject with the particle system to a parent object and try to rotate that gameobject.
change the 3D Start Rotation.
#Noblight is on the right track:
Depending on which shape you select, the particles should always fire the way the transform is pointing. Sphere is always 360, hemisphere is always within 90 degrees of forwards, cone always aims the way the transform goes.
Now, down in ForceOverLifeTime and VelocityOverLifetime, the settings for Local/Global really do pick which coord system to use. But not many people use those. For example, "thruster flames" are easy to make with a tight cone and sizeOverTime.
There are 4 particles in hierarchy. Every particle is actually rotated when the transform is rotated. But a particle has its own shape which determines the shape of it.
The explode blow can be changed by modifying the gravity modifier value. Here is the result :
A way to make this particle looks rotated is by altering Velocity over Lifetime the value in explode_blow particle. Here's the image :
Related
I have a Cinemachine Freelook camera and i want it similar to Skyrim, where the character's rotation follows where the camera is pointing, but only on the Y axis so that i can move my mouse and look at the character from up and down;
This video demonstrates how MrKrabs can move in 3 dimensions, but won't turn.
I already tried creating a blank object and putting it at the center of the character, then using transform.LookAt(Camera) to make it point to where the camera is, and finally getting the Y value of the object's rotation, inverting it with -transform.position.y and applying it to MrKrabs, but it didn't work: it was jittery and overall just a bad user experience, is there a way to turn the gameobject based on the camera's rotation? (having the camera always watching his back)
Something like this should do the trick.
transform.rotation = Quaternion.Euler(0, Camera.main.transform.eulerAngles.y, 0);
Beware that if your camera is a child of your object it will rotate with it.
I want to make the cube climb on the green blocks.I used Friction and Increased Force but Nothing happended.I wanted to make a game like Samsung Edge.
I am using RigidBody to control
If you want the cube to move by rotation I believe the function to use would be AddTorque() - documentation, it's a force you apply at a specific place of rigidbody. Then you have to experiment with friction and location of the torque you apply to get the effect you want.
I am trying to make a game with magnets. Each magnet has its own magnetic field which pulls the player towards the magnet.
The player should then be able to walk alongside the magnet on its entire side.
The player should not be pulled towards the center.
Right now I have done this by adding velocity to the player towards the magnet, this works fine.
The issue right now is that the player should rotate with his feet towards the magnet. Right now I can't figure out how to change the rotation of the player based on the rotation of the magnet. Which results in the player being on its side or upside down on the magnet in some case.
I am also using a third-person camera from unity standard assets, sometimes when the player is rotated the camera can only look up and down. To fix this I use a rotate function around World.Space.
You should get the position relative, the magnet as parent and your player as child. To do that you could create a different gameObject with the same position as the player, and set it as child to the magnet (or have a child on the magnet which you change its position (absolute position)).
Once you've done that, you normalize the localposition of the magnetChild and you make the player lookAt (there's a function in Unity) this vector + player.position. And you'll have to rotate the player 90º from the x-axis (to make that not the front of the player is looking to it, but the head).
I haven't tried it, but give it a try maybe it works. Something like:
magnetChild.position = player.position;
player.LookAt(player.position + magnetChild.localPosition.normalized);
player.Rotate(90.0f, 0.0f, 0.0f);
I am trying to fire projectiles from a player who is moving at very high speeds. The issue is that the bullets do not seem to inherit the angular velocity. If the player is moving in a straight line at 500 U/s, then the bullet correctly inherits that velocity and adds its own speed onto that:
GameObject bullet = Instantiate(projectile, gun.transform.position, gun.transform.rotation);
bullet.GetComponent<Rigidbody>().velocity = r.velocity + bullet.transform.forward *bulletSpeed;
However, if the player is turning really quickly, it does not inherit the rotational velocity, and the bullet looks like it veers off to the side.
How can I implement this? I tried assigning the angular velocity of the player to the bullet, but this just caused the bullet to spin while moving in the same direction.
Some extra details:
I am using rigidbody.MoveRotation() to rotate my player, but I manually calculated angularVelocity to assign it to the bullet
I tried moving the player with AddTorque(), but could not produce any results with the bullets
The immediate problem is that the projectile isn't part of the physics simulation until the moment you create and launch it, meaning the rotation of the player up to that point will not be able to influence its movement. I suppose this could work if you created the projectile at the start, attached it to the gun with a weak joint, then broke the joint and added to its velocity when it was fired - but it really would be simpler if you just "faked" it.
Applying Circular Motion
This is similar to a classic circular motion example you'd find in a physics textbook. When your bullet travels in a circle around the player (inside the gun), its normal path (if released) would be tangent to the circular path around the player. So when the bullet is fired (and hence released from the circular path), that angular velocity of the player would translate into a linear velocity of the bullet. Here's a simple diagram I put together that represents the situation with a ball on a string, being spun in a circle:
Getting the Tangential Velocity of the Bullet
You don't want to be applying any kind of angular velocity to the projectile after it has been launched - as you saw, this will only spin the projectile on its own axis. Rather, you want to apply an additional velocity vector to the projectile, which is tangent to the rotation of the player (and perpendicular to the facing of the bullet). So how do we do this?
Well, as per this website, the formula for tangential velocity at any point on something spinning in a circle is:
velocity = angularVelocity x radius
A key point to remember is that the angularVelocity is in radians, not degrees.
So, let's put this all together. Here's a general idea of how you might code this:
FireGun() {
// Assumes the current class has access to the rotation rate of the player
float bulletAngularVelocityRad = Mathf.Deg2Rad(rotationRateDegrees)
// The radius of the circular motion is the distance between the bullet
// spawn point and the player's axis of rotation
float bulletRotationRadius =
(r.transform.position - gun.transform.position).magnitude;
GameObject bullet =
Instantiate(projectile, gun.transform.position, gun.transform.rotation);
// You may need to reverse the sign here, since bullet.transform.right
// may be opposite of the rotation
Vector3 bulletTangentialVelocity =
bulletAngularVelocityRad * bulletRotationRadius * bullet.transform.right;
// Now we can just add on bulletTangentialVelocity as a component
// vector to the velocity
bullet.GetComponent<Rigidbody>().velocity =
r.velocity + bullet.transform.forward * bulletSpeed + bulletTangentialVelocity;
}
Hope this helps! It's never a bad idea to read up on some basic kinematics/mechanics when you're working with game physics, since sometimes relying on the game physics is actually more complicated than just devising your own solution.
I am trying to cast a ray along a sprite in Unity. I have Created an empty GameObject and made it as Parent to different Textures of Head, Hand, Chest etc of a Character to easily Animate it, Now for Melee Combat I would like to Cast a Ray along the Hand Texture while it Animates the Attack but I am Unable to get the Centre of the Hand Texture in the Scene.
I am trying to Access the Sprite by the following Code
Sprite Hand = gameObject.GetComponentsInChildren <Transform> () [4].GetComponentsInChildren <Transform> () [0].gameObject.GetComponent <SpriteRenderer> ().sprite;
This Code is Working for accessing the Hand Transform I verified by Drawing a Ray from the transforms centre
Rather than trying to find it at run time, just link it together in the prefab/gameobject. It's pretty simple to just expose it in the inspector then drag the sprite to the exposed variable. You could do a sprite or a transform, in the example below I used a transform, but if you need to get more data from it then go on ahead and use a sprite.
public Transform Head;
public Transform Hand;
public Transform Chest;
Then you can get the position with Head.position
If you are looking to check for collisions consider placing a collider at each location, then you can toggle them on/off when you want (so the hand collider is disabled unless if the character is punching, then you turn it on for the duration (or part of it) of the punch.) Then you can have a component on just that collider for doing damage or finding a wall or whatever you are trying to accomplish.