A couple of questions related to a top down shooter project

Hello everyone. I’m currently trying to create an atmospheric storydriven top down shooter. But since this is the first time i’m working with gdevelop, and i do not have heavy programing skills, i’m running into problems all the time.

Could someone give me a helping hand with how to:

-rotate the camera together with the player
-disable the mouse and let the player control the hero with the keyboard only (including firing the gun) and make it so, that the “up” key pushes the player forward only, instead of making him walk northwards and the “down” key should just make him walk backwards in whatever direction.
-add invisible walls the player can’t pass

I managed to let the cam rotate together with the player via Do =Hero.Direction() to angle of camera, but the camera rotates much too fast

I also dropped some 3D boxes (buildings) into the map, but the player just walks over them. Even if i apply behaviors like “PathfindingObstacle” to them. I also checked “Impassable obstacle” in the properties, but it has no effect.

Hum, better to try independant thing on each difficulty you have by example.

About rotating camera i’ve never tried to such thing so… idk, maybe direction() should be converted in radiant ? Basically you want your character always facing the same direction (forward) and the background might move around him ? Maybe you could show a game that works the same way on youtube ?

Disable the mouse is not recommended, at least until you’re development. What’s your difficulty with it ? there are action to show/hide mouse cursor and all condition/action necessary for it in the events editor.

Invisible walls can be done by several way : “false” image (basically a sprite fully transparent), or collision chack on background layer, or even hidden objets or 0% opacity on some sprite.

Did you take a look on examples provided with Gdevelop ? At least there is one example on pathfinding, and one example or two walls and collision… (try to modify the example to your needs and understand what you have to do on your own project).

I think this is actually that the player is rotating too fast and the camera is just following the player. With the top-down behaviour, there are only eight possible angles, so the rotation will always jump rather than be smooth.

You can make any object appear to be solid using the “separate two objects” action. You can find this in All objects>Position>Separate two objects

Your condition would be something like: Player is in collision with Wall
The matching action would be: Move Player away of Wall (only Player will move)

I don’t think the controllable player character can do pathfinding, so that may be why it doesn’t work.

Hi, I also want to make a top down shooter and I’m also new to Gdevelop, would you like to team up for learning purposes mostly if nothing else?

Thanks for your answers. Much appreciated.

Is there a way to replace the mouse cursor with an image (e.g. crosshair) or let the crosshair move always in front of the player with a distance of whatever pixels? There are several commands to push stuff towards a point or create an image at point xy, but either the crosshair moves out of the screen, doubles itself, flickers etc (depending on the method chosen). Just can’t get it to work.

@Zapata - I’m not online very often, but in general, why not

Ok, i figured out how to get the crosshair working. Just put the image file onto the map and apply the action Do =MouseX();MouseY() to the position of hud_crosshair. Now i got the problem, that the crosshair appears somewhat off the mouse cursor position. And this happens with pretty much everything. With all the objects using an action to determine an angle or position. I checked the center and origin positions of all the objects that are linked together and they seem fine.

I would also like to know, if it is possible to read text from a file and display it on the screen, so that i can store all the dialogs inside it and change languages or update it, without having to edit the game itself, when just using text objects.

Yes you can. But I don’t see why you need to do that. Because gd is an IDE itself, and you can just edit text variables as easy as in a notebook.

I did not know how to implement different languages via actions, but i figured it out now. The next question would be: How can i let the game handle only one of many objects with the same name e.g. i’m developing a gta 1/2 style game and i got cars named like “car_1_red” etc. The player should be able to get inside the car and drive around with it. I already figured out how to do it, but now i got the problem that, if “car_1_red” starts to move, all other "car_1_red"s within the map move accordingly. Do i really have to create tons of unique objects, even though they are basically the same?

When you create them, you can change a variable of the object to a different value. So you can add the variable to the condition.

No, but you may have to give each instance of the object a unique value (which can be tedious).

What you need to do is create the original car object and use the properties window to add a variable called something like “car_id”. Now place as many copies of the car object as you want in your scene.

Next you will have to click on each one you’ve placed (the properties window should change to read “instance properties”) and create the same “car_id” variable for it, but this time give it the unique value (or name) you want it to have. You’ll have to click and create for every instance, but thereafter you can use “Value of car_id is equal to…” as a condition to select individual cars.

Depending on how you set up your events, you may not need to do it this way as you could only move the one in collision with the player. That way you wouldn’t have to keep track of them as only one at any one time would be in collision with the player, so only that one would move. I think GDevelop automatically selects the instance involved in the collision to apply any actions to.

Thank you for your detailed answer. I’m pretty new to this, but i really like to get into it.

For some reason, the actions “Distance between two objects” and “Collision” won’t work on my car object. I attached a screenshot of my code below. Any advice on this?

I would also like to make an npc choose a random car near him (for example, someone who flees from the player) and get in. I’m using the code → Condition: “Pick a random group_car” (this group (group_car) includes all the cars in the map) and Action: Move testman to group_car.X();group_car.Y(). But it won’t work. Probably because i can’t apply the xy stuff to a group. But how to do it then?

Thanks in advance

I guess, in this situation you could use the object linking extension.

When the player get in to a car, simply link the actual car object to the player and when you move the care, take in to account only the one that is linked to the player. After, when the player get out of the car just simply delete the link.

This is exactly the kind of situation when the object linking extension is useful.

Maybe you could take advantage of the object linking in this case too:
Condition: “Pick a random group_car”
Action: link group_car to testman
Condition: Take in to account all group_car linked to testman
Action: Move testman to goup_car.X(), group_car.Y()

Also, don’t forget, when testman stop driving, delete the link in case you want him to pick an other random car again, but in case you want the npc to stick to the same car, you can leave the link.
But in case you have multiple npc’s looking for a car, accidentally they may pick the same car…
It could be fun actually more npc trying to get the same car :laughing: but in case you don’t want that, you may need to use an object variable for each car to store information if the car is picked by an npc already or not.

Just do the following :
At the beginning
For each group_car repeat: (this is an actual event, do not ignore it, you need to use this special for each event):
Do = 0 to group_car.Variable(picked)

This way you set the variable for each instance of each car in the map. And when you pick one, check the variable first:

Condition: “Pick a random group_car”
Sub-Condition: group_car.Variable(picked) = 0
Action: link group_car to testman AND Do = 1 to group_car.Variable(picked)
Condition: Take in to account all group_car linked to testman
Action: Move test man to goup_car.X(), group_car.Y()

This way, a car going to be linked only to a single testman, but there is an other problem. If a car is already picked, the testman need to attempt to pick an other random car again, and again, and again until it find a free one, to do that, you could put the actual car picking event in to an external event end just run it until the npc find a free car or you can use a while event to run the pick car events while the npc find one that is free.

As an alternative, at the beginning maybe you could just link a car to an npc manually through object variables.

Try something like this:

Testman:
Do = 1 to Variable(counter)
For each testman repeat:
Do = Variable(counter) to testman.Variable(ID)
Do + 1 to Variable(counter)

Group_Car:
Do = 1 to Variable(counter)
For each group_car repeat:
Do = Variable(counter) to group_car.Variable(ID)
Do + 1 to Variable(counter)

This events going to generate unique ID number for each testman and car.

Link each testman to the car with the same ID:
Main event: For each object testman:
-------Sub event:For each object group_car:
----------Sub even: testman.Variable(ID) = group_car.Variable(ID)
-------------Action: link group_car to testman

Move each testman to the linked car:
For each object testman:
Condition: take in to account all group_car linked to testman
Action: Move testman to group_car.X(), group_car.Y()

I might be wrong, but I think that if one object is physics and the other isn’t, then collision-checking doesn’t work. Might be a similar thing for distance measurements.

Thanks for your effort. But i think a have to cut the “pick a random car and drive around with it” part for npcs, since currently i don’t have a clue how to do it properly. Instead, i’m using a unique car for testman, right now. I get him to get “into” the car and start driving, using targetpoints. I have an object “editor_route”, which is a sprite, for that matter. Now, when i place two of them into the map an let testman drive with "Move testcar to editor_route.X(Variable(testman_car_routepoint)) etc, the car directly moves to the second routepoint i placed in the map. The first one gets ignored. I’m not even sure, if i did the variable thing above correctly. Again, do i have to create lots of editor_routes, or is there a way to let the car drive to an routepoint with variable x first, then routepoint with variable z etc.

No one does :laughing:
There are options that might work but to find the proper way of doing something is the real challenge even for pros.
Just think about the AAA games released with a complete rubbish AI and ridiculous bugs.

In case you try to move the vehicles toward a specific point, the most obvious way would be to check which point is next in-front of each vehicle. I guess it would require some math, so I can’t help you with that I’m afraid.
Obviously, you need to take in to account the direction of movement and on which road the vehicle is moving, which points going to be involved and which points are passed already and make the calculations which point would be next to move forward to for each vehicle. Technically, it would require to make a path system that I have never even tried, so I can’t help you with that.

But last time I’ve tried to make a GTA like traffic, what I decided to do is move the AI cars always forward toward their own angle whatever it is. In crossroads I was using a sprite and each time the AI car was colliding with it, the colliding car picked a random direction, left, right or forward. Obviously, if it was a left turn, the only option was to make the colliding car turn left, if it was a T junction, the only option was to turn left or right if it was just a slight bend then made the colliding AI car to turn a bit accordingly to keep follow the track. I was simply using different sprites for each case. Cross road, T juncsion, Left turn, Right turn and technically arrows to make the car turn a little here a little there in case the road was turning.
I was also using sprites that made vehicles randomly park down on the side of the road, on ramps, car parks…etc and for traffic lights and areas with speed limit to make vehicle stop or slow down.
Different type of cars was also moving at different speed and turned at different speed. For example a sport car was moving faster and turned faster than a truck, for that reason, I also had to keep in mind in each and every junction, bend and crossroad, which type of car how should behaving there in that specific location and also needed to make vehicles to change their speed in case something slower moving in-front of them.

It worked pretty good, but I don’t know if it the “proper way”, it was only a solution that worked for me for what I needed.
But it is involved lot of sprites and events and variables only to make vehicles move around.