A Simple Efficient View Movement System?

Don't know how to make something and can't find a tutorial? Ask for one here.

A Simple Efficient View Movement System?

Postby Turon » Thu May 25, 2017 9:01 pm

If someone could make a .ged of a movement system for a platformer that will follow the player up down left and right as effective as Yoshi's Island say but with cleaner code than in some older games and demos.
Yeah this is something I've been struggling on recently but I think something like this could help a lot of people (you know the folks that join the forum everyday and never post anything).
what should I put here?
kikiiscoolhi
User avatar
Turon
 
Posts: 818
Joined: Sun Jan 24, 2010 5:23 pm
Location: In Your Imagination
Score: 31 Give a positive score

Re: A Simple Efficient View Movement System?

Postby lcl » Mon May 29, 2017 10:07 am

I already explained this to you on Discord.

I provided you a code similar to this:
lcl wrote:
Code: Select all
double xx = player_collider.x - width / 2;
double yy = player_collider.y - height / 1.5;
double speed = distance(x, y, xx, yy) / 10.0;

MoveTo("Event Actor", xx, yy, speed, "Game Center", "");

And then you said that the view jitters around occasionally.

And then I told you what to do:
lcl wrote:Just add an if condition and make the MoveTo only execute if the view's distance from the (xx, yy) is greater than some limit value

And then you never returned to me on discord with your problem and instead seemingly proceeded to create this new topic. I was trying to help you already, and you were midway solving your problem so why do you start with the same question from the beginning again somewhere else? :o

Anyway, here's what I meant with my last remark:
Code: Select all
double xx = player_collider.x - width / 2;
double yy = player_collider.y - height / 1.5;
double speed = distance(x, y, xx, yy) / 10.0;

if (distance(x, y, xx, yy) > 5) // This
{
    MoveTo("Event Actor", xx, yy, speed, "Game Center", "");
}

The condition marked with a comment is new. It's meant to stop the view from moving if it already is very close to the position where it should be. This stops the jittering. The jittering is caused by the view not being able to reach the exact position of (xx, yy) and then vibrating around that position, desperately trying to reach it.

I hope this helps! :)
SABRE (semi-3D engine) official development topic: viewtopic.php?f=6&t=12644
A game project that utilizes SABRE: viewtopic.php?f=4&t=13297
User avatar
lcl
 
Posts: 2238
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 265 Give a positive score

Re: A Simple Efficient View Movement System?

Postby Turon » Thu Jun 01, 2017 2:39 pm

lcl wrote:I already explained this to you on Discord.

I provided you a code similar to this:
lcl wrote:
Code: Select all
double xx = player_collider.x - width / 2;
double yy = player_collider.y - height / 1.5;
double speed = distance(x, y, xx, yy) / 10.0;

MoveTo("Event Actor", xx, yy, speed, "Game Center", "");

And then you said that the view jitters around occasionally.

And then I told you what to do:
lcl wrote:Just add an if condition and make the MoveTo only execute if the view's distance from the (xx, yy) is greater than some limit value

And then you never returned to me on discord with your problem and instead seemingly proceeded to create this new topic. I was trying to help you already, and you were midway solving your problem so why do you start with the same question from the beginning again somewhere else? :o

Anyway, here's what I meant with my last remark:
Code: Select all
double xx = player_collider.x - width / 2;
double yy = player_collider.y - height / 1.5;
double speed = distance(x, y, xx, yy) / 10.0;

if (distance(x, y, xx, yy) > 5) // This
{
    MoveTo("Event Actor", xx, yy, speed, "Game Center", "");
}

The condition marked with a comment is new. It's meant to stop the view from moving if it already is very close to the position where it should be. This stops the jittering. The jittering is caused by the view not being able to reach the exact position of (xx, yy) and then vibrating around that position, desperately trying to reach it.

I hope this helps! :)

My apologies, I was forgetful and lazy. :oops: I'll look at it now. now that I think of it I remember the if (distance part but I somehow thought it was a user variable... But thanks for explaining again. :)
what should I put here?
kikiiscoolhi
User avatar
Turon
 
Posts: 818
Joined: Sun Jan 24, 2010 5:23 pm
Location: In Your Imagination
Score: 31 Give a positive score


Return to Tutorial Requests

Who is online

Users browsing this forum: No registered users and 1 guest