I am trying to make a part move in a certain direction without it being able to be pushed or rotated by the player's body. I am using bodygyro to stop the part from being rotated. The orientation of the part is 0, 90, 0. This is what the bodygyro properties are:
The problem is the bodygyro is rotating the part back to 0,0,0 orientation. How can I stop it from rotating the part back to 0,0,0 but also stop the part from being rotated by the player?
Add a bodyVelocity inside of the part to stop it from rotating. Make sure the angularVelocity is set to 0, 0, 0
Related
I am working on moving a Cube across the screen when I press an arrow and display two different animations depending on if it is moving or idle. I used a very basic translation to do this when I press the right arrow. I have two different animation states that work fine independently. One spins the cube when it is “idle” and the other makes to bounce up down in the “right” state. Both are 1 second animations. The idle animation spins the cube 360 degrees, and the right animation will move the cube up 1 unit then back down to its original position. Everything works well by itself. I included an image for the states for the animation.
Cube Animation States
In order to get the movement working with the animations I made an empty GameObject and made the cube a child if it. When the cube is idle it spins, and when I press right it moves and bounces up and down. The problem is when I release the right arrow the cube snaps back to its original position from the start of the last bounce animation. If I hold right for 10 seconds, and release it will only snap back to the beginning of the most recent iteration of the bouncing animation (not to when I started pressing right).
Does anyone know why this would happen? I tried changing some of the settings for the transitions, but it doesn’t seem like that is the problem.
Can you check that your idle animation modifying its position in any case.
First, you can't move the game object with animation.
you can have the rotate animation in the cube but not the translating part.
Because when the animations switch between the states the object will be moved to its original position.
solution:
-Create a script and attach the script to that game object.
-use translate functions to move the object
Sorry I know the title is really confusing.
Basically the camera and hands are nested under an empty object. This empty object is then used to rotate the character and teleport the character. Thing is, the camera is able to freely move around and away the empty object. Making rotation seem like you're running in a circle instead of just rotating. Then when you teleport it's a little offset. Like if you shoot the teleport beam straight down you move because it's teleporting the empty object to the camera which moves the camera.
So if the headset and camera aren't exactly on top of the empty object everything gets wonky. I understand the problem just can't figure out a solution.
I tried resetting the position on every teleport but you can still move away and spin in circles. As well as resetting resets the orientation and that's not exactly what I need.
Any help would be greatly appreciated.
There's a few ways to approach this. A crude, and not very elegant solution would be to parent your camera parent to yet another object, created in runtime, that would assume the position of the actual player camera when the rotation starts. You can reparent objects dynamically, so you could rotate this newly spawned object, which would give you the desired effect, and then loose the top parent when the rotation stops.
Alternatively you could move your camera parent as you rotate it, based on transforming the position relative to the player camera position. A bit more elegant but there's probably a few lines of math that you would have to write
I'm having an issue where my character is facing 90 degrees away from the (first person) camera. So when I move the character, the model is turned 90 degrees to the right instead of facing forward. (Pic 1)
Since the camera is a child of the player, if I rotate the character -90 degrees, the camera rotates with it. If I rotate my camera back 90 degrees, the controls get messed up (the W to go forward becomes W to go right, etc.) (Pic 2)
Is there anything I can do to either change the default rotation of the
For reference, I am using this FP Controller torah horse(.)com(/)First-Person-Drifter-Controller-for-Unity3d-1 (that uses a cylinder, so doesn't have the same rotation issue)
I'd advise you to put a script on the Camera instead of making it a child of the player. This gives you more freedom in how the Camera behaves.
Actually, looking at your pictures again... Why not just set the Camera behind the player correctly, instead of rotating the player. When you have the Camera as s child it will be responsive to the parents transform, but it wont mimic. It will follow with the same offset as it starts with. So instead of rotating the player, which messes up the controls, simply put the Camera where you want it from the start.
I'm using the SneakyInput Joystick to move my sprite, and TMX maps for my game. I added auto-camera-movement to my app, so the hero sprite is always visible. When I go through my map, the joystick goes off the screen (it stays where it's original position is). I made a HUD so that the joystick is always at the same position, and doesn't move along with the map. The joystick shows up on screen fine, but when I drag it it doesn't move my hero.
I've made HUDLayer a CCLayer in GameLayer, which is where I'm making the moveHero method. The joystick works, but when I move it across the map, the auto-camera-movement works, but the joysticks stay in there same position, and are out of view pretty soon. I know the problem is that I do [self setCenter....blah blah blah]; instead of only setting Level1 as the center. How do I only move the camera for Level1, and not HUDLayer?
Here is a link I found on how to use this class. It seems fairly straight forward. I think you want to change the method - (void)moveHero to:
- (void)moveHero; {
[self applyJoystick:leftJoystick toNode:hero forTimeDelta:1.0/60.0f]];
}
as it seems you already kept a reference to the left Joystick when you initialized the HUD.
Ok, if you want to centre the HUD layer based on those 2 points (the joystick and the other item), you need only lay them out in a 2D grid, and figure out the centre point from there. I'll assume you are working with an iPhone screen in landscape mode. Then the dimensions are 480x320. The centre of this screen is (240, 160), and so, I would use this centre for my joystick and other HUD item. So I would probably set my joystick at (10, 10), and my other item (assume dimensions of this item to be (x, y)) at ((470 - x), 10), which would give the items both a 10 pixel boarder around them.
Hope that Helps!
I have a problem regarding CCFollow. I am using CCFollow along with CCParallaxNode. I have added layers to parallax node and then apply runaction: on parallax node.
[pn runaction:[CCFollow actionWithTarget:sprite worldBoundary:CGRectMake(0, 0, 5600, 320)]];
but using this the sprite always runs at middle of screen. Is there any way to keep it at left of screen and also layers follow this sprite?
Thanx.
If you want your player to remain on the left side of the screen, then lock the players X position to a specific region that makes sense. You should also be moving the background and other elements of your game, not your player (with exceptions, to the players position visually on the screen).