Jump to content

Change camera position (help: I'm desperate :C)


nicknico00

Recommended Posts

Please guys HELP MEE!

 

I have been googling for days before I came here and I've tried almost everything, but I didn't find a way to change the third-person-camera position. What I want to do is to move it in front of the player's eyes, like it was in first person, being able to see the player's body. help please: I'm getting crazy  :-\ :'(

 

thank you in advance.

Link to comment
Share on other sites

width=638 height=359http://stech1.firstpost.com/tech2images/640x359/proportional/jpeg/gallery/2013/feb/yunomeme_281836203546.jpg[/img]

 

Y U NO UPDATE?!?!?!??!

 

Seriously tho... we alredy have peek on 1.9, and ppl are still on goddamn 1.7...

 

Solution:

You will have to replace camera entity on game startup. You can find the field in Minecraft.class and replace it with extension with changes you need.

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

Link to comment
Share on other sites

Thank you very much!

 

I spawned a new EntityCamera that extends EntityLiving and set the renderViewEntity to this. It works!

But now the problem is: the entityCamera's position and rotation are based on player's position and rotation, and sometime, when I move my mouse to move the head in game, the camera starts spinning very fast and I can't stop it D:

Do you know what it could be?

 

And sometimes I get an error like invalid entity attacked, when I click, and it crashes.

Any idea?

 

Thank you

Link to comment
Share on other sites

the renderViewEntity have to extend entityLivingBase, so EntityLiving is fine (better EntityFlying).

 

I fixed the first issue: my camera didn't like rotationYaw > 360 or < 0  ;D, so I had to adjust player's rotationYaw before to use it.

Now it doesn't spin anymore ;).

 

The code I used:

 

Camera class

public class MAEntityCamera extends EntityFlying {

public MAEntityCamera(World p_i1595_1_) {
	super(p_i1595_1_);
}

}

 

RenderPlayerBase class (I'm using Player API)

public class MARenderPlayerBase extends RenderPlayerBase {
private MAEntityCamera camera;

public MARenderPlayerBase(RenderPlayerAPI renderPlayerAPI) {
	super(renderPlayerAPI);
}

@Override
public void renderFirstPersonArm(EntityPlayer p_82441_1_) {

	World world = Minecraft.getMinecraft().theWorld;
	EntityPlayer player = Minecraft.getMinecraft().thePlayer;

	if(!(Minecraft.getMinecraft().renderViewEntity instanceof MAEntityCamera))
	{
		//change renderViewEntity to camera
		if(camera != null) Minecraft.getMinecraft().renderViewEntity = camera;

		else
		{
			camera = new MAEntityCamera(world);
			camera.setPositionAndRotation(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch);
			world.spawnEntityInWorld(camera);

			Minecraft.getMinecraft().renderViewEntity = camera;
		}
	}
}

@Override
public void renderPlayer(AbstractClientPlayer paramAbstractClientPlayer, double paramDouble1, double paramDouble2,
		double paramDouble3, float paramFloat1, float paramFloat2) {

	super.renderPlayer(paramAbstractClientPlayer, paramDouble1, paramDouble2, paramDouble3, paramFloat1, paramFloat2);

	//change renderViewEntity to player when rendering in third-person
	if(Minecraft.getMinecraft().gameSettings.thirdPersonView > 0) Minecraft.getMinecraft().renderViewEntity = Minecraft.getMinecraft().thePlayer;
}
}

 

EventHandler class

public class EventHandler {

@SubscribeEvent
public void updateCamera(RenderHandEvent event) {

	if(Minecraft.getMinecraft().renderViewEntity instanceof MAEntityCamera)
	{
		EntityPlayer player = Minecraft.getMinecraft().thePlayer;

		//place camera in front of players's eyes
		double distanceX = -0.4, distanceY = -0.5,  distanceZ = 0.4;
		double x = Math.sin(Math.toRadians(player.rotationYaw))  * distanceX;
		double y = Math.sin(Math.toRadians(player.rotationPitch)) * distanceY;
		double z = Math.cos(Math.toRadians(player.rotationYaw))  * distanceZ;

		//adjust rotationYaw
		if(player.rotationYaw > 360) player.rotationYaw -= 360;
		if(player.rotationYaw < 0) player.rotationYaw += 360;

		Minecraft.getMinecraft().renderViewEntity.setPositionAndRotation(player.posX + x, player.posY - 1.63 + y, player.posZ + z, player.rotationYaw, player.rotationPitch);
	}
}
}

 

It works good, but I have to optimize it because of a few problems...

For example I can't interact with the blocks i see in the center of the camera, because the player is not watching exactely there, and so i often get the error: "trying to attack an invalid entity".

 

Do you know how could I fix this?

thank you very much

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Whether you are a fan of Hypixel Bedwars, SkyWars and PvP gamemodes like that, well you would enjoy this server! We have a very fun and unique style of PvP that a lot of our players really enjoy and we want to bring this server to more players like you! Yes you reading this post haha. Introducing, the Minezone Network, home of SUPER CRAFT BLOCKS. We've been working on this server for over 4 years now. Here is what we have to offer: SUPER CRAFT BLOCKS: This has 3 different gamemodes you can play, Classic, Duels and Frenzy. Each mode offers over 60 kits to choose from, along with a total of over 60 maps, allowing for various different playstyles on each map. There are also random powerups that spawn on the map which can include Health Pots, Bazookas, Nukes, Extra Lives and way way more! There is also double jump in this gamemode as well, which makes PvP a lot more fun & unique. You only need a minimum of 2 players to start any mode! Classic: Choose a kit, 5 lives for each player, fight it out and claim the #1 spot! Look out for lightning as they can spawn powerups to really give you an advantage in the game! Duels: Fight against another random player or one of your friends and see who is the best! Frenzy: Your kit is randomly selected for you, each life you will have a different kit. You can fight with up to 100 players in this mode and lets see who will be the best out of that 100! All the other stuff from Classic/Duels apply to this mode as well like powerups. We have 2 ranks on this server too, VIP and CAPTAIN which has a bunch of different perks for SCB and other things like Cosmetics and more.   SERVER IP: If this server has caught your interest in any way, please consider joining and you will NOT regret it! Bring some of your friends online for an even better experience and join in on the fun at: IP: minezone.club Hope to see you online!   SERVER TRAILER: https://www.youtube.com/watch?v=0phpMgu1mH0
    • The mod give new blocks  
    • I will a Mode for 1.21 in this Mod give new block, items and dimensions   
    • Remove Optifine For shader support and similar, use Embeddium + Oculus
  • Topics

×
×
  • Create New...

Important Information

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