Jump to content

Recommended Posts

Posted (edited)

Hello, I know 1.9.4 is fairly old version, but I figured not much has changed since then regarding the tick/render mechanics, so answers for current version should apply as well.

 

I am working on something that controls player's yaw/pitch and I bumped into following problem:

* I do most work when onPlayerTick() occurs - which basically means to calculate next pitch/yaw correction, add it to Minecraft.getMinecraft().thePlayer.rotation(Yaw|Pitch) and move on to next iteration.

* My computer has steady 60 FPS, there are 20 ticks per second, the pitch/yaw rotation updates do not look smooth, because I am only allowed to change it once per 3 frames rendered.

* I know it is possible to make it look smooth, because it looks smooth when I control the yaw/pitch with my mouse when playing. 

* This video illustrates my problem.

 

I did some Googling and found out, that I might be able to use partialTicks and subscribing to drawScreen() method, so I tried onFrame method, which does following:

// Helper variables 
static float previousYaw = 0;
static float previousPitch = 0;
static float desiredNextYaw = 0;
static float desiredNextPitch = 0;
static float desiredYaw;
static float desiredPitch;

public static void onFrame(float partialTicks)
{
	Minecraft.getMinecraft().thePlayer.rotationPitch = (desiredNextPitch - previousPitch) * partialTicks + previousPitch;
	Minecraft.getMinecraft().thePlayer.rotationYaw = (desiredNextYaw - previousYaw) * partialTicks + previousYaw;
}

 

Then I subscribe this to GuiScreenEvent.DrawScreenEvent event like this:

@SubscribeEvent
public void drawScreen(GuiScreenEvent.DrawScreenEvent event)
{
	// Help with smoothing transitions between yaws/pitches
	if (this.currentTask.taskName.equals("DawdleAroundTask"))
	{
		DawdleAroundTask.onFrame(event.getRenderPartialTicks());
	}
}

 

And finally, I still, every onPlayerTick occurrence, during ClientTickEvent.Phase.START, run method of the DawdleAroundTask.runTick() which looks like this (yaw/pitch corrections are unimportant and therefore I removed them to provide minimal readable sample):

// Mimicking pre-tick-phase
Minecraft.getMinecraft().thePlayer.rotationYaw = desiredNextYaw;
Minecraft.getMinecraft().thePlayer.rotationPitch = desiredNextPitch;
// /Mimicking pre-tick-phase

/* HERE IS WHERE I EXPECT A MUCH MORE LOGIC TO BE DONE AND THEREFORE PRETEND PRE-TICK-PHASE AND POST-TICK-PHASE */

// Mimicking post-tick-phase
desiredYaw += getRandom()[0];
desiredPitch += getRandom()[1];

// Corrections
desiredNextPitch = previousPitch - pitchDistance;
// Mimicking post-tick-phase

 

When I run this now, it still looks like it is updating only every third frame/once per tick, which is not nearly enough. How do I make it look smoothly? I would like it to look as if I am controlling the mouse and the game smoothly turns player around when I move the mouse. Is it possible that I am using wrong events? 

 

I am sorry for rather a long post, but I feel like that just reading the text part describing what events and what methods I use, could tell enough to you, ultra smart people around here, on what I am doing wrong. I always come here to beg for help as a last resort and I seriously admire the level of understanding and insight into it that you guys here have. Looking forward to your replies!

Edited by DeadPix
Added coma so the second bullet-point in list makes more sense. + wording + shortified unnecessary code
Posted

I'm not sure the draw screen event is really the best one. It should probably work, but I'd try something like the RenderWorldLastEvent. In any case make sure you confirm that it is firing at the refresh rate.

 

The other possible issue is client versus server side. The server has nothing running at the client refresh rate so it can only make decisions at the tick rate, and furthemored any change in pitch and yaw initiated by the server can at best happen at the intervals that it can send packets to the client. 

 

So maybe you're already doing this, but I think what you have to do is change the pitch and yaw in an event like RenderWorldLastEvent. 

 

I would start with a simpler implementation to debug this. What happens if you simply add 1 to yaw in the render event? Forget all the randomness, the desired target and the partial ticks. Just see if you can get smooth steady transition with simply adding 1. 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

I’m pretty sleep deprived right now, and I don’t know if this is what your looking for but I had a similar issue (I was using xyz instead of pitch/yaw). I wrote a method that gets the coordinates to render at very exactly. 

 

Have a a look at the entityPos variable in

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/client/render/tileentity/TESRWire.java

 

and the method that creates it (getEntityRenderPos) at

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/util/Utils.java

 

The object (“Position”) it returns is pretty self explanatory. A double accuracy point in 3D space

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.