Jump to content

[1.12] Direct change of entities moving vector due to collision with block


ConfusedMerlin

Recommended Posts

Good evening,

 

it's me again. This time I have something... well, its a bit stupid I think. 

 

The testing environment: Okay. Again, there is a picture to look at. That red cross is made out of custom blocks, which are no full blocks (as one might have expected; this isn't a texture trick). Their aabb has been resized to fit their visual appearance, aaand... north is up. Oh, these blocks are non solid, so you can walk through. 

 

The target situation: Every entity that collides with the block should be pushed back (force may vary) in the general direction it came from, or better: at a rough 90° angle from the surface it touches. 

 

The experiment: I found onEntityCollidedWithBlock() and started fooling around with whats possible with this function. And somehow it condensed towards some kind of repulsing block; like the slime, which you can use for high-jumping. But from all sides. So I could not reuse the onLand() Method, or what its name was, but instead went to look to get this done using onEntityCollidedWithBlock().

I tried out a lot of things; firstly I misunderstood what the vector methods where for. When hearing "vector" I think of some kind of movement, but after I teleported myself around to crazy extends, I realized that it might not be the movement-redirection I was looking for. Than I found the motionXYZ fields, and the moveRelative() method. Last one was foolproof to use, but when I looked sideway and tried to apply negative forward momentum, my player got accelerated alonside the "wall" of repulsing blocks. I used this to send Zombies to the moon, by digging a 3x3 hole with walls out of repulsor blocks and let 1x1 free in the middle, used an egg at the first block and... wheeeeeeeeeeee. :)

 

Ehem, back to topic. After "moveRelative() didn't yield the result I hoped for I went back to the three motion-fields. Because I still suck working with the blocks facing-stuff, Went for something else and got the coordinates of the block and the entity colliding with it, looked for the difference (block - entity) and got usually a value of 1 or -1 for x, y or z. 

After finding out, that you move with negative preposition when going towards the smaller coordinate value and via versa, I just added entityIn.setVelocity((holoX-entiX)*-1,(holoY-entiY)*-1,(holoZ-entiZ)*-1)

 

Here is that method - the super-call seems not to have any influence to the success or fail

 @Override
    public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {


        double inputX= Math.round(entityIn.motionX*100)/100;
        double inputY= Math.round(entityIn.motionY*100)/100;
        double inputZ= Math.round(entityIn.motionZ*100)/100;

        double entiX = entityIn.getPosition().getX();
        double entiY = entityIn.getPosition().getY();
        double entiZ = entityIn.getPosition().getZ();

        double holoX =  pos.getX();
        double holoY =  pos.getY();
        double holoZ =  pos.getZ();

        double outputX=(holoX-entiX)*-1;
        double outputY=(holoY-entiY)*-1;
        double outputZ=(holoZ-entiZ)*-1;


        try {
           worldIn.getPlayerEntityByName(entityIn.getName()).sendMessage(new TextComponentString("holo: x: " + holoX +", y: " + holoY + ", z: "+ holoZ + ";"));
           worldIn.getPlayerEntityByName(entityIn.getName()).sendMessage(new TextComponentString("enti: x: " + entiX +", y: " + entiY + ", z: "+ entiZ + ";"));
           worldIn.getPlayerEntityByName(entityIn.getName()).sendMessage(new TextComponentString("dif: x: " + (holoX-entiX) +", y: " + (holoY-entiY) + ", z: "+ (holoZ-entiZ) + ";"));
           worldIn.getPlayerEntityByName(entityIn.getName()).sendMessage(new TextComponentString("input vel: x: " + inputX +", y: " + inputY + ", z: "+ inputZ + ";"));
           worldIn.getPlayerEntityByName(entityIn.getName()).sendMessage(new TextComponentString("output vel: x: " + outputX +", y: " + outputY + ", z: "+ outputZ + ";"));

            entityIn.setVelocity((holoX-entiX)*-2,(holoY-entiY)*-2,(holoZ-entiZ)*-2);

        }catch(Exception e){
            //just keep on going in case something is going insane
        }

        super.onEntityCollidedWithBlock(worldIn, pos, state, entityIn);
    }

 

The problem: Okay. That should do the trick, I think. Lets say, in theory that seems to work. In "reality" (or in game) something unexpected does happen: when touching the blocks from north or west (moving to south or east), I just clip though the blocks (that looks kind of strange), while the "debugging output" to the chat-console tells me, that the "new" motionXYZ should be the correct value. 

Even more strange, when comming from south to north, from east to west, from up to down (and from down to up... combine both for a grand shaking) the redirection works perfectly. It will keep drops jumpuing until they despawn, or the player jumping until you went off. 

But these two directions (north->south and west->east) wont work. The best that happens is, that I slowly... warp through the blocks, just to get slinged away at the other side. 

 

So... I know this is far from being productive work in any form, but I'm afraid that I need to use velocity and vector handling later to a greater extent, so it cannot hurt to know what one can do wrong or understand wrongly. 

 

 

Greetings, Merlin 

 

repulse.png

Link to comment
Share on other sites

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • LAYANAN DAFTAR TRANSTOGEL ! WA : 082213952901 SEARCH GOOGLE > TRANSTOGEL  
    • If you’ve ever experienced the sinking feeling of losing funds online, you’re not alone. Enter recovery services like ADWARE RECOVERY SPECIALIST, the heroes of the digital age who help individuals track down and retrieve lost funds. These services act as modern-day sheriffs in the Wild West of the internet, bringing justice to those who have fallen victim to online scams and fraud. In a world where online transactions are as common as selfies, the need for recovery services is more pressing than ever. Individuals worldwide are vulnerable to various online schemes, from investment fraud to phishing scams. Recovery services provide a glimmer of hope for those who have lost money, offering a chance to recover what's rightfully theirs and restore faith in the digital realm. The beauty of recovery services like ADWARE RECOVERY SPECIALIST lies in their global reach. Email: Adwarerecoveryspecialist@auctioneer. net  Regardless of where individuals are located worldwide, these services extend their virtual arms to help victims of online fraud. From bustling metropolises to remote villages, no corner of the world is beyond the grasp of these modern-day Robin Hoods. Thanks to the wonders of globalization, recovery services have transcended geographical boundaries to serve individuals worldwide. The interconnected nature of the digital world means that help is just a click away, bridging gaps between nations and bringing relief to those in need. In a world where borders are becoming increasingly blurred, recovery services stand as beacons of accessibility and assistance. When a broker stole from me and withheld access from me for five months, I had no idea that I would be able to recover my trading money back. I'm relieved that I was able to get my money returned without any issues. The impact of recovery services like ADWARE RECOVERY SPECIALIST extends far beyond individual wallets. Communities worldwide have experienced a renewed sense of trust and security, knowing that there are dedicated professionals working tirelessly to recover their lost assets. These services not only bring financial relief but also restore faith in the integrity of the digital world. Trust is the cornerstone of any successful recovery service, and building credibility in a global market can pose unique challenges. ADWARE RECOVERY SPECIALIST strives to maintain transparency and reliability in all its interactions, earning the trust of clients worldwide. ADWARE RECOVERY SPECIALIST can be talked to through:  Website: www.adwarerecoveryspecialist.expert  Telegram: @ADWARE_RECOVERY_SPECIALIST
    • The game wont start and keeps crashing everytime I hit play "The game crashed whilst rendering overlay Error: java.lang.IllegalAccessError: failed to access class com.mojang.blaze3d.platform.GlStateManager$TextureState from class net.coderbot.iris.gl.IrisRenderSystem$DSAARB (com.mojang.blaze3d.platform.GlStateManager$TextureState is in module minecraft@1.18.2 of loader 'TRANSFORMER' @724b939e; net.coderbot.iris.gl.IrisRenderSystem$DSAARB is in module oculus@1.6.4 of loader 'TRANSFORMER' @724b939e)" How do I get it to stop? Log error here: https://pastebin.com/byv1dR54
    • In case anyone happens on this with the same issue, I was able to overcome it. After re-reading @Paint_Ninja's last post numerous time, it finally dawned on me that he was referring wholly to the forge installer, which has nothing to do with the packaged modpack installer. As such, I downloaded the new copy of the forge installer and copied it to my linux host, then opened a second ssh session and prepared a cp command to move the new (correct) installer over to the install directory where I was installing the modpack. After the modpack installer had just about finished retrieving files, I overwrote the installer.jar file with the correct one in a seperate ssh session. The modpack (packaged) installer then used that jar to install forge with the included files, and the install finished as I would have expected. Thanks all!
  • Topics

×
×
  • Create New...

Important Information

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