How to make Godot Camera2D not rotate along with the player? - rotation

I have a simple side-scrolling platformer where the player is a ball, and I want him to rotate as he moves to look like he is rolling.
However, I have a 2D Camera set up so the player is at the bottom center of the screen. I want the player to stay there, but when I move the player the camera moves in circles along with the player.
How can I stop the camera from moving around?

A few options come to mind:
Presumably the player character is a PhysicsBody2D (e.g. a KinematicBody2D) with a Sprite or similar. And the Camera2D is a child of the PhysicsBody2D. Well, rotate the Sprite. That way the rotation does not affect the Camera2D. Of course, if the rotation is driven by physics, then this option isn't helpful.
Well, there is no reason to make the Camera2D be a child of your PhysicsBody2D to make it follow it. Instead, you can use a RemoteTransform2D that pushes its position (with update_position = true), but not its rotation (with update_rotation = false) to another Node2D. And then you make your Camera2D a child that another Node2D.
Let us say you don't want to have something as child of your character PhysicsBody2D at all. In that case, you can try a PinJoint2D. Set your node_a to the character PhysicsBody2D, and your node_b to some RigidBody2D, and then the Camera2D can be a child of the RigidBody2D.
Or you can solve it with a script. You can add a Node2D and on its _physics_process you have it copy the global_position of your character to its own global_position, so that it follows it. Then make the Camera2D a child of the Node2D.

Related

Why will my physics 2D raycast not display or work correctly?

Basically i wanted to make a raycast for jumping but for some reason the distance of the raycast is wrong and never changes and the position of it is so wrong i cant even seem to find it:
ray2D = Physics2D.Raycast(transform.position, -Vector2.up, .1f, GroundedLayers);
Debug.Log(ray2D.distance);
isGrounded = groundCheck();
Grounded layers do not include the player, distance always returns as 0, grounded is always false and the gizmos line only draws when i open the prefab and not at all in the scene:
here the distance is set to .1f but displays the same as 1f
(EDIT: ok so i checked and for some reason the raycast happens around 0, -1 even tho thats nowhere near the player transform?)
Try Vector2.down instead?
Alternative things to try:
Is the player in the scene the same as the prefab?
Increase the distance.
Add a new GameObject at the feet of the player, reference that in your script and call the Raycast from there.
Is ray2d a RayCastHit2d?
Are your ground object tags correct, including all grammer/caps?
Try outputting in debug, ray2d.collider.name to see what you're actually hitting.
If you're using a rigid body, try rigidbody2d. position instead of transform.position
Do you have the player selected in the hierarchy? This is needed to see the gizmos.
I found that the raycast was detecting an invisible trigger so i had to put it on another layer :)

object shift in blender

I have two animated objects
Soldier and weapon
Animations are already created, but there is a problem, the weapon is not in the hands of a soldier.
How do you move the weapon along with its entire animation? So that I don't have to edit the whole animation frame by frame
It looks more or less like the picture, as you can see the pickaxe is lower than the hand
Set the 3D cursor to objects origin
Now add a new empty to the scene, it should be added at the objects origin
Parent the object to empty
Now move the empty to the desired location and the whole animation will be moved as well
idk how to add new empty to the scene.
I'm trying to do like that:
On. 3D view -> pose mode -> 3d cursor
what next?

Group of objects on top but added to a camera

As a precision I already noticed threads about this but didn't find a way to achieve exactly what I need.
Basicaly I have a board of objects that I need remaining always on top of everything but also attached to the camera.
I first tried to add the group to the camera and it stayed as wished always in the viewport. But in this configuration the group of objects still be a part of the scene so while zooming to regular objects in the "editor" the board goes into/among these objects of the scene.
My second trial was based on this thread and work wonderfully in order to get all of the board objects rendered above everything. But on such a configuration when rotating around the axis (with orbit control) both scenes rotates. So I tried to update the foreground scene with coordinates of the camera but the update was not immediate and this scene is flickering (I suppose that while rotating the update function is not called immediately).
My best wish would have been to "attach" the foreground scene to the camera so that it would stay on top and sticked on the screen/viewport but I don't even know if it is possible and how to do that (as only groups of objects seem to be capable to be attached to the camera).
I am really stuck on that point. Thanks you for any help!
If this is what you need,
just set object.material.depthTest = false; and object.renderOrder = 1000; for all objects you need to be always on top and attached to the camera.

Transition between different points of views (SCNCameras) in SceneView

I've built a basic scene for SceneKit, including several SCNNodes with geometries, SCNLights, and an SCNCamera. I would now like to add functionality whereby the point of view shifts between different camera positions when the user taps on the screen.
What is the best way to achieve this? Should I include several SCNCameras in the scene and switch sceneView.pointOfView between them? Or should I rather update the position (and orientation) of a single camera. Also, how can I specify the transition path from moving from the old to the new camera position, i.e. use animation for the transition.
changing the pointOfView of the view is the easiest way. But if you want to control the path you will have to move the camera yourself. You can do that with SCNAction or by using CoreAnimation explicit or implicit animations.

Using Cocos2d i need to set a sprite boundaries so it cant go off screen, how do I do this?

im using cocos2d to create a game and i want to set my sprite a boundary so that it cannot go off the screen on the line of x. What code can i use to do this. I dont want the sprite to be bounced back in the opposite direction i just want it to stop.
http://www.raywenderlich.com/475/how-to-create-a-simple-breakout-game-with-box2d-and-cocos2d-tutorial-part-12 explains how to set boundaries.
Shamelessly pasted code follows:
// Create edges around the entire screen
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0,0);
_groundBody = _world->CreateBody(&groundBodyDef);
b2PolygonShape groundBox;
b2FixtureDef groundBoxDef;
groundBoxDef.shape = &groundBox;
groundBox.SetAsEdge(b2Vec2(0,0), b2Vec2(winSize.width/PTM_RATIO, 0));
_bottomFixture = _groundBody->CreateFixture(&groundBoxDef);
The last line setAsEdge sets the edge :D
However, if you want no bouncing, you can eiter set your moving sprite to
spriteDef.restitution = 0f;
or d that on the edge itself, depending if your moving sprite has to bounce on other stuff or not.

Resources