Thanks for the suggestions. Whilst GetNodeType did work, it still left me with having to pass in a string rather than a class. I'll stick to creating multiple scenes and attaching them to an exported variable on the tank.
nathanjwtx

- Oct 9, 2019
- Joined Jul 15, 2018
- 0 best answers
If I pass bullet.tscn into another method, can I derive the class (i.e. bullet.cs) from the PackedScene in order to access the properties and methods on the class?
This was a classic example of PICNIC syndrome: Problem In Chair Not In Computer!
I had declared the Shoot method in 2 different places and the code was calling the one with a single arguement signature first because it was higher in the scene tree. (I think scene tree is the right phrase)
My signal is connected in the code using:
_enemyBeige1.Connect("Shoot", this, "_on_Shoot");
Then I emit it via
EmitSignal("Shoot", "Fire!");
This works fine except i want to pass 2 parameters through to _on_Shoot but I get
Error calling method from signal Shoot
.I did remember to update the _on_Shoot method to take 2 parameters. I've done this before in previous projects so I know it is possible but I just can't make this work.
Also, what is the benefit of declaring the params/arguements when declaring the signal?
[Signal] delegate void Shoot(string p1, string p2);
Do you need the background to register the event? If not, you could just remove the code.
How do you mark a post answered?
- In [Beginner] How do I convert mouse position to a cells x & y coordinate? eg: So I can do a SET_CELL?
Oh that's awesome! I was calculating that manually! Thanks :+1:
I toyed with going the GDScript route as I'm a huge Python fan but I use C# in my daily job and figured it would be best to stick with something I already know vs trying to learn something new.
So regardless of the rotational transform displayed, the origin doesn't change?
Why would the need to do the offset in Y vs X change though?
yep, looks like it :)
Actually I kinda gave up on the arrow idea and just drag the tank sprite for the time being. Seems simpler to implement.
- Edited
Gave up with trying to paste it in code tags :/
[Gist](http:// "Gist")
using Godot; using System; using System.Collections.Generic; public class Player : KinematicBody2D { private bool _dragged = false; private Vector2 _current; private List<Vector2> _moves = new List<Vector2>(); public override void _Ready() { // set initial position of unit _current = new Vector2((float)(Math.Floor(this.GetPosition().x / 64)) * 64 + 32, (float)(Math.Floor(this.GetPosition().y / 64) * 64 + 32)); _moves.Add(_current); } public override void _Process(float delta) { // SelectedTank(); } public override void _Input(InputEvent @event) { if (@event is InputEventMouseButton mouseEvent) { if ((mouseEvent.GetPosition() - this.GetPosition()).Length() < 32) { if (!_dragged & mouseEvent.ButtonMask == 1) { _dragged = true; } else { _dragged = false; } } } if (@event is InputEventMouseMotion mouseMoved) { if (_dragged) { MoveTank(mouseMoved.GetPosition()); } } } private void MoveTank(Vector2 mousePos) { Vector2 tile = new Vector2((float)(Math.Floor(mousePos.x / 64)) * 64 + 32, (float)(Math.Floor(mousePos.y / 64) * 64 + 32)); float priorX; float priorY; // GD.Print(tile); if (_moves.Count == 0) { _moves.Add(tile); } if (tile != _current) { _current = tile; priorX = _moves[_moves.Count - 1].x; priorY = _moves[_moves.Count - 1].y; this.Position = tile; if (_moves.IndexOf(_current) > -1) { _moves.RemoveAt(_moves.Count - 1); } else { _moves.Add(_current); } if (_moves.Count > 1) { var norm = (_current - _moves[_moves.Count - 1]).Normalized(); GD.Print(norm); if (_current.x < priorX) { this.SetRotationDegrees((float) 90); } else if (_current.x > priorX) { this.SetRotationDegrees((float)-90); } else if (_current.y > priorY) { this.SetRotationDegrees((float) 0); } else if (_current.y < priorY) { this.SetRotationDegrees((float) 180); } } } } }
- Edited
:/
How are you handling the click detection?
i've run into an odd issue with sprites and rotating them. The Kenney tank sprites all point downwards and so need rotating 90 to face Godot's 0 degrees. No big deal. However, this played havoc with my code that rotates the barrel. I then remembered in a @KidsCanCode tutorial he said he pre-rotated them. I switched to those assets and bingo, no wierd rotation issues. so 2 questsons: 1. why does the starting rotation impact code to rotate to a given position? It seemed to be 90 degrees off each time (visually speaking as the the calc is in radians) 2. in the unrotated assets I had to set the offset in X whereas in the rotated ones I had to set it in Y to get it in the same starting position. This one is really confusing. I guess I could correct the rotation calc to allow for 90 but i don't understand why I would need to
- Edited
I'm working on a square grid based game and want to have a "click n drag" arrow to select the destination square but I'm not sure where to start with that. Any ideas?
The gear icon allows me to edit the post but change it to Q&A.
But I know what to do for next time ?
@Megalomaniak said: To find posted questions with no replies press the button on the left side of the forum titled "Unanswered", answer them by replying. You can mark a reply as an answer only in topics you have created(unless you are an admin).
Where is the option to set a post as "Question" and where is the button to accept an answer?
I guess this idea never took off? I' have a hankering for one of the Godot pins I've seen a folks with in pics on Twitter etc. at GDC. Plus a T-Shirt would be cool :)
https://www.youtube.com/results?search_query=godot+platform
some of these tutorials might help