+ 13

Game - avatar movement

I want to make a game in which you have a avatar, and you can walk around a map. The question is: How do I make the avatar always be in center even when he is walking around the map?

18th Sep 2020, 12:09 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
16 ответов
+ 8
Since you're a veteran, I will simply say that if it were up to me, I would see how far horizontal/sideways parallax scrolling gets me. I would hope that it could be attached to the horizontal scroll just as well as the traditional vertical scroll, but I haven't tried it, so I could be very wrong. (Has been on my bucket list though.)
19th Sep 2020, 10:35 AM
Janning⭐
Janning⭐ - avatar
+ 10
As Bagon has pointed out, game engines can handle that for you so that the logic of moving your avatar instead of the map remains intact and sound. Under the hood, however, the engine ultimately ends up shifting background graphics across the screen. Take Flappy Bird implemented via JS as a crude example, we are really moving the pipes towards the bird instead of the other way around. https://github.com/CodeExplainedRepo/FlappyBird-JavaScript
18th Sep 2020, 12:21 PM
Hatsy Rei
Hatsy Rei - avatar
+ 8
You move the map instead of avatar. :>
18th Sep 2020, 12:12 PM
Hatsy Rei
Hatsy Rei - avatar
+ 6
If you use any game engine you can configure the camera to do that with just a few clicks, tho otherwise you might have to move the whole map instead of an avatar
18th Sep 2020, 12:13 PM
Bagon
Bagon - avatar
+ 6
Do you want such kind of a movement? https://code.sololearn.com/WdULpHU5nr5y/?ref=app
18th Sep 2020, 1:08 PM
Namit Jain
Namit Jain - avatar
+ 6
Mirielle[ InAcTiVe ] Yes, but under the default premise that Alex wants to "make the avatar always be in center even when he is walking", I'd say that we are discussing in additonal context now.
18th Sep 2020, 2:02 PM
Hatsy Rei
Hatsy Rei - avatar
+ 5
I have been thinking at that but to be honest it doesn't sound good. Moving the terrain under someone's feet. 😂 edit: If this is the only choice then I'll do it.
18th Sep 2020, 12:14 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 4
As everyone pointed out - MOVE THE MAP. But move it in a way that it will create illusion of moving player.
18th Sep 2020, 1:50 PM
Raj Chhatrala
Raj Chhatrala - avatar
+ 4
•Try three.js •simple enough then babylon.js or other •understand the camera perspective and scene rendering. •Your 90% of the doubts will be solved https://gamedevelopment.tutsplus.com/tutorials/creating-a-simple-3d-endless-runner-game-using-three-js--cms-29157 HAPPY coding 😃 Hope this was helpful
18th Sep 2020, 4:40 PM
Gone
+ 3
Mirielle[ InAcTiVe ] is right. Moving the map is not a long term solution. It may trick the player into thinking that he is making the avatar move, but the moment I need to add colision between the avatar and other objects from the map, the code becomes a mess. I will continue to search for solutions.
18th Sep 2020, 2:50 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 3
I made a quick demo using Janning⭐ 's idea. It works exactly as I wanted. I put a div (1000vmin/1000vmin) inside another div which has the exact width and height as the screen. I used the scrollTo() function to change the scroll posion of the camera, when the avatar is in the middle of the screen. (wip, events to be added) https://code.sololearn.com/WbQca4Xk604n/?ref=app
21st Sep 2020, 3:08 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 3
💜 Alex Tușinean 🍇 👍👌 That's nicee 🙌 (Somewhat similar to my idea ig 🤔) And here's another code that I tried to make! Only key presses 😄 https://code.sololearn.com/WBKgXWEicB3E/?ref=app
21st Sep 2020, 4:05 PM
Namit Jain
Namit Jain - avatar
+ 2
I don't think that moving the map is very different from the player movement! If we want to show that the player is moving at a speed of 'a' along the x-axis and 'b' along the y-axis then to make the viewers pretend that the player is moving, the map has to move exactly '-a' along the x-axis and '-b' along the y-axis
18th Sep 2020, 2:10 PM
Namit Jain
Namit Jain - avatar
+ 1
i did not understand the question
19th Sep 2020, 7:56 AM
akarsh
akarsh - avatar
0
Camera following the avatar
18th Sep 2020, 2:38 PM
Shadoff
Shadoff - avatar
- 1
Please start with basic code base. Have a look at Quintus game engine
19th Sep 2020, 7:02 PM
Sooraj Vinodan
Sooraj Vinodan - avatar