Giter VIP home page Giter VIP logo

Comments (13)

VaclavElias avatar VaclavElias commented on June 6, 2024 1

Let's do it. Do we have a relevant section in the manual? Should it go to UI section? Wouldn't you mind creating a PR, maybe just simply summarising the subject?

from stride.

VaclavElias avatar VaclavElias commented on June 6, 2024 1

Thank you. Let's put it under Physics. I will assist with the rest, I can check with others if it is the right location. Also, you can just dump content to the new docs page, and I can align and format further, just to save your time :)

from stride.

Doprez avatar Doprez commented on June 6, 2024

Oh, its it the bad jitter in the FPS tempalte? whenever you move around and look at something it looks like bad FPS?

from stride.

jhimes144 avatar jhimes144 commented on June 6, 2024

So I'm new to stride so I haven't use any other template, but yes - especially when you strafe right or left and move your mouse to keep looking at an object - you get horrible screen tearing. In fullscreen mode, you don't get it at all.

EDIT: Just pulled up the third person template - also get the screen tearing. Although, its less noticeable because of how the camera moves.

from stride.

Doprez avatar Doprez commented on June 6, 2024

Ok, assuming I understand what the problem is this time lol I have dealt with the same issue. It had to do with the Camera being directly attached in some way to the Physics body and updating its transforms based on that update interval.

The way I fixed it was the below steps:

What I had to do was create a SmoothFollowAndRotate script that just lerped between 2 entities at a certain speed.

[ComponentCategory("Utils")]
[DataContract("SmoothFollowAndRotate")]
public class SmoothFollowAndRotate : SyncScript
{
	public Entity EntityToFollow { get; set; }
	public float Speed { get; set; } = 1;

	public override void Update()
	{
		var deltaTime = (float)this.Game.UpdateTime.Elapsed.TotalSeconds;
		var currentPosition = Entity.Transform.Position;
		var currentRotation = Entity.Transform.Rotation;

		EntityToFollow.Transform.GetWorldTransformation(out var otherPosition, out var otherRotation, out var _);

		var newPosition = Vector3.Lerp(currentPosition, otherPosition, Speed * deltaTime);
		Entity.Transform.Position = newPosition;

		Quaternion.Slerp(ref currentRotation, ref otherRotation, Speed * deltaTime, out var newRotation);
		Entity.Transform.Rotation = newRotation;
	}
}

Then in your scene you have to unparent the camera from the player controller and add that smooth follow and rotate component to follow a new pivot point on your character controller.
image

This will break things in certain scripts since they use direct references to a CameraComponent but I will list the fixes below.

PlayerInput.cs

change
public CameraComponent Camera { get; set; }
to
public Entity Camera { get; set; }

Utils.cs

change
CameraComponent camera
to
Entity camera,
and change

camera.Update();
var inverseView = Matrix.Invert(camera.ViewMatrix);

to
var inverseView = camera.Transform.WorldMatrix;

FpsCamera.cs

Remove


        /// <summary>
        /// Gets the camera component used to visualized the scene.
        /// </summary>
        private Entity Component;

and change

        private void UpdateViewMatrix()
        {
            var camera = Component;
            if (camera == null) return;
            var rotation = Quaternion.RotationYawPitchRoll(Yaw, Pitch, 0);

            Entity.Transform.Rotation = rotation;
        }

to

private void UpdateViewMatrix()
{
    var rotation = Quaternion.RotationYawPitchRoll(Yaw, Pitch, 0);

    Entity.Transform.Rotation = rotation;
}

from stride.

jhimes144 avatar jhimes144 commented on June 6, 2024

@Doprez

Thank you for all of this, looks like you accidently copied and paste twice here, mind if you correct it? I got the rest of the changes in.

and change

    private void UpdateViewMatrix()
    {
        var camera = Component;
        if (camera == null) return;
        var rotation = Quaternion.RotationYawPitchRoll(Yaw, Pitch, 0);

        Entity.Transform.Rotation = rotation;
    }

to

    private void UpdateViewMatrix()
    {
        var camera = Entity;
        if (camera == null) return;
        var rotation = Quaternion.RotationYawPitchRoll(Yaw, Pitch, 0);

        Entity.Transform.Rotation = rotation;

}

from stride.

Doprez avatar Doprez commented on June 6, 2024

Ah yep, fixed!

Also worth mentioning that my best speed for for the follow script is 25, seems to be the smoothest without falling behind.

from stride.

jhimes144 avatar jhimes144 commented on June 6, 2024

Whoa. Well, I think I definitely screwed it up somewhere because I'm getting wild behavior.

I'm going to come back tonight and just rewrite the camera and movement system, while taking in your smooth lerping technique into account. For me, I think the player control and camera should all be in one script. Thanks a ton for the help! If you have a sample project with these changes let me know as well.

Sounds like this is probably not a v-sync issue.

from stride.

Doprez avatar Doprez commented on June 6, 2024

Here is the project with the fixes included: https://github.com/Doprez/smooth-fps-template/tree/main

It also had a change with some light shafts that cause an initial lag on loading the game but it should clear up after 2-3 seconds.

from stride.

jhimes144 avatar jhimes144 commented on June 6, 2024

@Doprez You are a saint! That fixed it. It was a bit laggy at first, but then when I also set the MinimumElapsedTime to Zero - it became butter smooth, and the experience is now identical to fullscreen mode. This really should be the new FPS 1st person template too, its much much smoother.

Its full steam ahead for my wpf/avalonia overlay. I think I definitely will open source it. The other wpf/avalonia solutions involve the attempt of rendering the UI framework in Stride, mine just uses win32 apis to get it to work.

EDIT: The only thing not working in this code is that gun shots do not hit when you are moving the character, I'm sure i can figure out a fix to that though.

from stride.

VaclavElias avatar VaclavElias commented on June 6, 2024

@Doprez, do we need to document this?

from stride.

Doprez avatar Doprez commented on June 6, 2024

@Doprez, do we need to document this?

Probably wouldnt hurt, I know this isnt the first time I have seen someone with this issue and even when I first started this drove me nuts because I didnt know why lol.

from stride.

Doprez avatar Doprez commented on June 6, 2024

Yep, I can take some time later to do this. I am not sure where would be the right spot though.. maybe Physics?

from stride.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.