I have a shooting darts (KinematicBody2D) that will need to stick on a moving wall (staticbody2D).
I wants to let the dart stick on the wall, and change position according to how the wall move (currently my wall is moved by updating its position).
However, the dart does not follow fully the moving path of the wall.
I end up adding pinJoint2D, but setting the node via gdscript only give me an error
Invalid set index 'node_b' (on base: 'PinJoint2D') with value of type 'StaticBody2D (StaticBody2DWall.gd)'.
My code in dart node for setting up pinjoint2d goes as below:
var slide_count = get_slide_count()
if slide_count:
var collision = get_slide_collision(slide_count - 1)
var collider = collision.collider
lif collider.is_in_group("wall"):
$PinJoint2D.node_b = collider
Anyone please help. Please let me know if there's a better practice.
The node_b member is a node path, not a node. Try the following:
$PinJoint2D.node_b = collider.get_path()
Related
I am having problem figure out how the normal work.
I am using godot4 RC1.
I created a staticbody3D and want to place a 3dobject standing upright like how we stand on earth.
this is my code for the staticbody3d:
func _on_input_event(camera, event, position, normal, shape_idx):
player.global_position = position
var q = Quaternion.from_euler(normal)
player.basis = q
basically I use the code to capture the mouse_over position on the staticbody3d and place my player(Mesh3d) at the position, and align the player basis to the normal.
if mouse at the top of the planet, it turn out ok.
but anywhere else, it just gone hay wire:
How can I resolve this?
I'm trying to create an overlay in ArcGIS that has moving graphics/symbols which are updated by coordinates received from roving devices. I'm able to display a simple symbol initially but cannot get it to move on the map. My test code is
GraphicsOverlay machineOverlay = new GraphicsOverlay();
MainMapView.GraphicsOverlays.Add(machineOverlay);
MapPointBuilder rdLocation = new MapPointBuilder(150.864119200149, -32.3478640837185, SpatialReferences.Wgs84);
SimpleMarkerSymbol sRD1234 = new SimpleMarkerSymbol()
{
Color = System.Drawing.Color.Red,
Size = 10,
Style = SimpleMarkerSymbolStyle.Circle
};
Graphic graphicWithSymbol = new Graphic(rdLocation.ToGeometry(), sRD1234);
machineOverlay.Graphics.Add(graphicWithSymbol);
// here the red circle is displayed correctly on the map
rdLocation.SetXY(150.887115, -32.357600);
rdLocation.ReplaceGeometry(rdLocation.ToGeometry());
// here I expect the red circle to move but it doesn't
Do I need to trigger an event to "re-render" or refresh the overlay, or what do I need to do to get the graphic to move on my map?
There was a similar question here and the answer was "just update the geometry" which is what I'm attempting to do, but with no success.
If there is an entirely different or better approach to moving markers on a map please suggest, I'm just getting started in the ArcGIS runtime.
Thanks
After a lot of searching I replaced one line of code and its now working
//rdLocation.ReplaceGeometry(rdLocation.ToGeometry());
graphicWithSymbol.Geometry = rdLocation.ToGeometry();
It seems I misunderstood the function of ReplaceGeometry(). Any clarification on this would be helpful.
First of all, I'm new to programming in general so I'm kind of assuming there's a simple answer to this question, I just couldn't seem to find it anywhere.
I'm making a simple platformer game with enemies that move toward the player. I used this code in the enemy's script underneath the physics process to get the player position:
player_position = get_parent().get_node("Player").get_position
However, upon the player being queue_freed when health reaches 0, the game crashes immediately and I get a null error due to there being no Player node. How can I work around this?
You could just set $Player.visibility to false instead of freeing, or you could check if the player exists first using get_parent().has_node("Player")
When you destroy the player, the physics process function is still trying to get the player node, even though it doesn't exist. So, as Lucas said, you could replace:
player_position = get_parent().get_node("Player").get_position
with something like...
if get_parent().has_node("Player"):
player_position = get_parent().get_node("Player").get_position
(Before setting player_position, it will check if the player node even exists)
I think you could use weakref (documentation here).
If you declare a weak reference:
var player_ref: WeakRef = null
and store that reference:
func store_player_node():
var player_ref = weakref(get_parent().get_node("Player"))
Then you can access that reference later:
if player_ref.get_ref():
player_position = player_ref.get_ref().get_position
Weakref has advantage over using get_parent().get_node("Player"). Let's imagine the following scenario:
Player dies and its node is removed from the parent node's children.
New node is created with name Player and added to the scene tree at the same place as the dead Player.
get_parent().get_node("Player") will return a node and the code will not crash. However, it will be a new Player node, not the old one, and I think this is usually undesired.
I hope this helps!
I am making a top down zombie shooter in Phaser 3.
I am using the moveToObject function to make zombies follow the player. Now I want to make healthbars for the zombies. I have read that you can use containers to make the enemies and healthbars move together but I am having trouble to move the container with moveToObject.
Is it possible to move a container with the moveToObject function or should I use something else instead?
It looks like the moveToObject method looks for an individual item's velocity and according to the API Docs, Container doesn't hold an overall velocity. But each object added to the container should have a velocity.
The quick way to fix this is to iterate through your container's objects and tell each item to moveToObject. I'm adapting an example from Phaser Labs here:
var block = this.physics.add.image(600, 300, 'block');
var clown2 = this.physics.add.image(20, 200, 'clown');
var clown = this.physics.add.image(200, 300, 'clown');
var container = this.add.container(10, 200, [clown, clown2]);
for (var x = 0; x < container.list.length; x++) {
this.physics.moveToObject(container.list[x], destination, 200);
}
This might not be the cleanest solution but it should help accomplish what you want to do. The Phaser API docs say moveToObject works with a GameObject, which includes Container. This might be worth reporting as a bug to see if there is a way the base code can be fixed to allow containers to work. You can report the issue here if you'd like.
What i am trying to accomplish is to have a user click on the canvas and the sprite(player) will move to that location and STOP once it reaches that location.
Currently i have the player can click and it will continue in that path which is the default function.
update: function() {
this.player.rotation = this.game.physics.arcade.angleToPointer(this.player);
if (this.game.input.activePointer.justPressed()) {
// move on the direction of input
this.game.physics.arcade.moveToPointer(this.player, this.playerSpeed);
}
}
Maybe its simpler than i think but i cant seem to find a solution.
point in the right direction would be useful :)
I think you look for something like this:
Using Tweens (something very interesting about Phaser)
OR
Using
Arcade Physics (which is an example similar to yours)