Can you activate a method on an Area2D node with the player's raycast2D in Godot? - game-development

I created a sort of old style jrpg movement system with a 3 character party. The first character (the player) uses a raycast for checking of surrounding tiles and movement.
I want the player to come close to a shop tile and hit a button to open a dialog.
Player is in the middle, shop is above him, like so:
How would I activate a custom function on the shop tile?
I tried using raycasts and signals. The shop is an Area2D tile.
Is it even possible to trigger an Area2D on_entered signal with a raycast?
The default signals seem to be incorrect for this use, but so do custom signals.
There is probably something very simple I'am missing.
Thanks for any help.

You could check what the raycast is colliding with. Since it looks like you are placing an Area2D on top of a TileMap, why not make the shop a StaticBody2D instead of a tile, and attach the shop script. It would be typical for game objects other than the walls to not be in the TileMap.
Somewhere with your player's movement code:
if Input.is_action_just_pressed("interact"):
var collider = raycast.get_collider()
if collider != null:
if collider.has_method("open_shop"):
collider.call_deferred("open_shop")
I am assuming here that the raycast is properly updated already in your movement code, either by the raycast property enabled being true, or having a call to force_raycast_update().
Here, raycast should be replaced with any reference to the player's Raycast2D, and "open_shop" should be replaced with the function name (still as a string literal) from the shop script you wanted to call.

Related

Getting Contact Information with Tiles in Godot

Can I somehow get information that the player has touched a specific tile located in the resource (tilemap.res)?
It is necessary to determine which tile it stands on (for example, on land or in water)
It depends on what kind of behavior you're expecting. There's two major ways to do this:
In each individual script that you want to be affected by the tiles, get the tile it's on every time it moves, then run the logic directly from there.
As above, get the tile the unit is on each time it moves, but instead of just running the logic every time, emit a signal whenever the tile changes, and keep the current tile cached so you can check when it's on a new tile; have the TileMap itself attach to the signal, and when it receives the signal, act on the Node2D until it leaves. This is what I'd do.
The exact method to find the tile is TileMap.world_to_map(TileMap.get_cellv(Node2D.position))--you just need to have the Node2D and the TileMap, and you can get both in the same function using the above two methods.
Technically, you could also procedurally add Area2Ds to the tilemap based on the tiles at various positions using TileMap.get_used_cells_by_id, making sure that the ID is the one that has the special behavior, then attaching the TileMap to those areas' body/area_entered and body/area_exited and using that, but spamming a whole lot of Area2Ds isn't necessary when you can check the tile a Node2D is on directly.

Unity2d; How to raise(lift) camera during game mode at a fixed y axis minimum

I may be making this harder than what it really is, but I am also pretty new to developing games. Currently I am making a practice scene to get back used to the unity engine as I have not had time to use it since last summer. My issue is that I can not figure out how to lift the camera in game mode. Notice my photo below, and how much of the "underground" is showing. I want to raise the camera to keep it at the very least a specific y axis value, so that I can make less of the ground visible, and more of the background visible. If I am over complicating this, please also let me know. Thank you
If main camera is still then just lift the camera in scene view you can see changes in game view.
Or if camera moves with respect to player then you have to use a script and attach it to camera and get a reference of player transform in the script and according to the player position change position of the camera. Add an offset value in y component of the camera.

Taking Control of ARCamera on Unity3D with Vuforia

The position and rotation of Vuforia's ARcam are determined by their algorithms to give the AR effect. I'd like to know how to do the following:
When some object is clicked the camera goes to some specific position (for that I need to somehow take control of the camera).
Also have to possibility to yield control of the camera back to Vuforia.
You'll want to use a second camera in this instance. Position the second camera at the AR Camera position, then adjust the depths to make the new camera the view that you see. Then you can tween its position to the predefined one you have.
Do the reverse to get control back to the AR Camera.

Three.js 3rd person camera

I'm trying to create a 3rd person camera view in three.js
I'm using the THREE.FirstPersonControls(); on my camera. Then setting the rotation and positions of my "player" objects to be the same as the camera with some offsets.
This does not seem to work.
What i'm more wondering is if I should be adding my FirstPersonControls to the camera and then rendering the "player" infront of it. Or adding the controls to the player then making the camera always point at the back of the player?
EDIT:
I've tried setting the player object to be a sub object of the camera using camera.add(player);
but moving the camera around is not moving the player. I thought adding an child element would mean they move together?
EDIT 2:
I took another approach of adding both the camera and the player to a group then adding my 1st person controls to that group... Now both the camera and the player do get rendered. But it's completely thrown off how the first person controls worked. (e.g. looking down goes left etc etc)
Thanks for any help,
James
First of all, the Controls were designed to be controlling a camera, and not an object. And since by default, objects look "up" the z-axis, and cameras look "down" the z-axis, it is unlikely that the Controls will work as expected when applied to something other than a camera.
Secondly, the Controls are part of the examples, and not the library, so they are not officially supported. You are free to hack away at them.
One way to achieve what you want is to make the camera a child of your player. Something like this:
player.add( camera );
camera.position.set( 0, 50, 100 );
You may, in your render loop, need to set:
camera.lookAt( player.position );
Then you want to control the player with the mouse or keyboard. Your best bet is to write your own controller to do that. There are plenty of examples on the net.

How to create the land (hills) like iOS game 'Contre Jour'?

How to create the land (hills) like iOS game Contre Jour? (Using Box2d and OpenGL)
My ideas:
Physics (Box2d)
I think we have array of bodies or fixture.
When we to touch screen, determine touch location.
If the touch location is not far from land, we begin to scan the array of bodies, and are looking for a body with coordinates closest to touch Location.
When case a touch Move, move the right body to a new coordinate (body->SetTransform(...)).
What do you think, efficient to use a large number of bodies? And find for the right body by coordinates?
Graphics (OpenGL)
There is an array of vertices and triangles created by drawing the land (hills)?
Is this true?
You can use the function b2World::QueryAABB to get a list of the fixtures in a given area, then check those for the best option. The Box2D testbed does this to find out which fixture to grab with the mouse so you could check out that source code. See also: http://www.iforce2d.net/b2dtut/world-querying
To move the body you can indeed use SetTransform, which would be good if the object does not need to interact with anything along the way. Another option might be to SetLinearVelocity to a velocity that will move the body to the dragged-to point in one time step. This is a better method if you want a continuous drag with the object being able to bump into things as it moves, because it does not teleport the body instantly to the finger position. If the body is a bullet body then it also prevents the user from dragging things through other objects, eg a static wall. Remember to set the velocity to zero when the finger is lifted :)