Jump to content

[1.6.4]Making a player move


starwarsmace

Recommended Posts

And by "move" you mean teleport entity (player) 2 blocks in some direction (probably front), or actually just a normal movement like on "FORWARD" key that will end after 2 blocks? If the second one, well, are you also considering player walking speed (potions/soulstone) or just want player to walk 2 blocks with "normal" speed? Also: you do understand that if you are alredy walking e.g. forward, and make player walk "again" forward (by rightclicking) this will not stack - I mean, it depends if you will launch single movement or movement over tick.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

And by "move" you mean teleport entity (player) 2 blocks in some direction (probably front), or actually just a normal movement like on "FORWARD" key that will end after 2 blocks? If the second one, well, are you also considering player walking speed (potions/soulstone) or just want player to walk 2 blocks with "normal" speed? Also: you do understand that if you are alredy walking e.g. forward, and make player walk "again" forward (by rightclicking) this will not stack - I mean, it depends if you will launch single movement or movement over tick.

 

I meant teleport and no I didn't realize it won't stack but thats fine.

I'm back from being gone for... I think its been about a year. I'm pretty sure nobody remembers me, but hello anybody who does!

Link to comment
Share on other sites

Well, there are many ways to do the teleportation thing (because "normal" walking process would be harder - that's why I asked).

You could make setPositionAndUpdate() and call it inside your onItemRightClick() method.

Rest of the code (x,y,z) coords are just math thing, so I am guessing you know how to get entity position, don't you?

I am not sure about rotation after teleportation, so if it wont be same as beforte event, you could save players rotation yaw, and then set it after the teleportation event.

Edit:

Well, just read:

/**
     * Move the entity to the coordinates informed, but keep yaw/pitch values.
     */
    public void setPositionAndUpdate(double par1, double par3, double par5)
    {
        this.setLocationAndAngles(par1, par3, par5, this.rotationYaw, this.rotationPitch);
    }

So, no, Yaw stays the same.

Also: If you want to make sure that player wont be travelling inside of blocks, you can get world max y for (x/z).

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Well, there are many ways to do the teleportation thing (because "normal" walking process would be harder - that's why I asked).

You could make setPositionAndUpdate() and call it inside your onItemRightClick() method.

Rest of the code (x,y,z) coords are just math thing, so I am guessing you know how to get entity position, don't you?

I am not sure about rotation after teleportation, so if it wont be same as beforte event, you could save players rotation yaw, and then set it after the teleportation event.

Also: If you want to make sure that player wont be travelling inside of blocks, you can get world max y for (x/z).

 

Ok will try this.

I'm back from being gone for... I think its been about a year. I'm pretty sure nobody remembers me, but hello anybody who does!

Link to comment
Share on other sites

Really?

width=661 height=553http://upload.wikimedia.org/wikipedia/commons/thumb/8/85/Coord_planes_color_point_pl.svg/661px-Coord_planes_color_point_pl.svg.png[/img]

 

You set posZ twice.

Fixed:

player.setPositionAndUpdate(player.posX+2, player.posY, player.posZ);

Also:

(x,y,z) are coordinates of entity in the WORLD, not in entity coord plane. That means that adding +2 will move your entity in world's grid.

You need to either use Math() to get direction that will be added to (x,z) or... Well, this is pretty much only option :o

 

Edit: And yeah - diesieben07 alredy answered, sry.

 

Edit: For getting player's rottationYaw check out debug in GuiIngame (search for this.mc.mcProfiler.startSection("debug");).

Or maybe they added some function that returns rotation automatically? (well, i am using my own Util from 1.1 or earlier so, I don't know)

 

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Really?

width=661 height=553http://upload.wikimedia.org/wikipedia/commons/thumb/8/85/Coord_planes_color_point_pl.svg/661px-Coord_planes_color_point_pl.svg.png[/img]

 

You set posZ twice.

Fixed:

player.setPositionAndUpdate(player.posX+2, player.posY, player.posZ);

Also:

(x,y,z) are coordinates of entity in the WORLD, not in entity coord plane. That means that adding +2 will move your entity in world's grid.

You need to either use Math() to get direction that will be added to (x,z) or... Well, this is pretty much only option :o

 

Edit: And yeah - diesieben07 alredy answered, sry.

 

Edit: For getting player's rottationYaw check out debug in GuiIngame (search for this.mc.mcProfiler.startSection("debug");).

Or maybe they added some function that returns rotation automatically? (well, i am using my own Util from 1.1 or earlier so, I don't know)

 

Just realized I did it twice. Silly mistake. cheesy.gif

 

 

Also I've ,never really used the Math(). So could you give me some code to work with? Thanks.

I'm back from being gone for... I think its been about a year. I'm pretty sure nobody remembers me, but hello anybody who does!

Link to comment
Share on other sites

Dude... Saying "never really used the Math()" is like saying you are a 12 year old and suck in school.

Java Math() is just a math. Can't help here if you don't understand what a f(x)=sin(x) is.

I can only tell you how to "kinda" make it.

1. float yaw = mc.thePlayer.rotationYaw; //returns total spin yaw of player during Entity existance (read: moment you join the world)

2. Wrap your yaw into smaller values (http://en.wikipedia.org/wiki/List_of_trigonometric_identities)

3. MathHelper.wrapAngleTo180_float(yaw);

4. Do the math for x and z coordinate - well, you can make it even using Pythagoras and sin(x) - I prefere better ways.

5. You got your x and z, now launch:

player.setPositionAndUpdate(player.posX + x, player.posY, player.posZ + z);

1.7.10 is no longer supported by forge, you are on your own.

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.

Announcements



×
×
  • Create New...

Important Information

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