LegendLength Posted July 20, 2016 Posted July 20, 2016 I am trying to move the player by a small amount in x,y,z during each game tick. I have done various searches on this forum and stepped through the code but still struggling to find the correct way to do it. Currently I'm able to set the player's motion during the player tick end event and it works well. But if I try to set position instead then the player will bounce a bit in the direction and then reset back. I assume it's not getting sent to the server. I also tried player.setPositionAndUpdate() but I believe that is for when you are teleporting a player. The aim of this is for normal movement (trying to implement physics on the player using a certain type of numerical integration , hence the need to set position rather than motion). Feel free to offer a solution for a higher minecraft version instead. Quote
Draco18s Posted July 20, 2016 Posted July 20, 2016 Player position is determined by the server. Player motion is determined by the client (and sent to the server which the server then uses to update the player's position). So if you want to use .setPositionAndUpdate you have to do it on the server. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
LegendLength Posted July 20, 2016 Author Posted July 20, 2016 Thanks. I did test test player.setPostionAndUpdate() but wonder if it's the 'correct' way. I noticed there was no interpolation when doing it this way. From my research it seems that method is used mainly for setting the player's position during a teleport event. Do you think it will still handle interpolation, collision detection etc. properly? I'm also not sure if it is the right way because it seems to send a network update straight away, whereas using MotionX etc. may do network updates a little differently. Quote
Draco18s Posted July 20, 2016 Posted July 20, 2016 On 7/20/2016 at 6:02 AM, LegendLength said: Thanks. I did test test player.setPostionAndUpdate() but wonder if it's the 'correct' way. I noticed there was no interpolation when doing it this way. No there's not because interpolation is handled by the client's motion values. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
LegendLength Posted July 22, 2016 Author Posted July 22, 2016 I think I found a solution so i'll give some details in case anyone needs it in future: The goal is to move the player by position rather than using motion. The problem is if you directly call something like setPositionAndUpdate() you don't get the benefit of minecraft's position interpolation, among other things. After looking through the movement code I saw that the Entity.motionX fields are simply added to the Entity.posX fields every tick. There are no special physics derivations etc. going on. This means you can simply set motionX to be your position delta and the game will move the player by that amount. It allows you to use any kind of physics system you want because most of the advanced ones (like Runge Kutta) require you to adjust position, rather than velocity. So it would look something like this: @SideOnly(Side.CLIENT) @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent event) { if (event.player.world.isRemote) { if (event.phase == TickEvent.Phase.END) { EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer; // calculate all the physics you need Vector3F deltaPosition = myCalculateDelta(); // you can store current velocity in your own variable somewhere // move player player.motionX = deltaPosition.x; player.motionY = deltaPosition.y; player.motionZ = deltaPosition.z; } } } Quote
Ernio Posted July 22, 2016 Posted July 22, 2016 Just don't use this: EntityClientPlayerMP, generally speaking - you should aim at lowest abstraction layer possible - EntityPlayer (EntityPlayerMP for server or AbstractClientPlayer for client if you need). Quote Quote 1.7.10 is no longer supported by forge, you are on your own.
coolAlias Posted July 22, 2016 Posted July 22, 2016 Also, PlayerTickEvent is most definitely NOT client-side only. Please read this post on @SideOnly. As for movement, there is no interpolation at all (built in, at least) if you use any kind of #setPosition-type functionality, but there is if you set player motion. Adding / setting player motion is probably the best way. Quote http://i.imgur.com/NdrFdld.png[/img]
LegendLength Posted July 22, 2016 Author Posted July 22, 2016 Ok thanks for the tips from both of you. I have only just started looking at the client / server issues for mods so that will come in handy. Quote
Recommended Posts
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.