HelloI need to cast to TopDownController to get Sword Slash variable. It works at server side. But its not working at clients. How can i solve it. What can i use instead of get player controller or is there any way for casting or any other way to make this work in multiplayer. Can someone help me please ?
PlayerController is not replicated to other clients other then local machine (if im not mistaken) for security reasons as users can do anything with there PC memory. use PlayerState which is replicated extension of PlayerController and should contain all public information (not tied to pawn itself) on player that all other clients can access. Same goes with GameMode, there GameState for exact same reason
GetFirst should be the fastest as it iterates and return first find and stop looping, if you in pawn you should get controller via GetController as it is more direct. If you really worried with performance, just do it once somewhere and keep the pointer.
So upon further exploration, all of the solutions above seem to use World to get the first player controller. The two most direct options then seem to be ()->GetFirstPlayerController() and using the PlayerControllerIterator. Seeing as GetFirstPlayerController uses PlayerControllerIterator, it just comes down to how much you control you want of your search, but GetFirstPlayerController would probably do just fine.
I am sort of new to C# scripting and I am wanting to make my player move using the WSAD keys. I was able to get my player moving however when I try to move forward it acts like there is a barrier, I have searched far and wide on the Scripting API to try and find a solution. If anyone could help me that would be amazing, thank you.
Well something I noticed is that you should be using transform.forward instead of Vector3. Currently you are moving forward in Global space and not the players forward looking direction.
(This applies to all directions not just forward)
So I figured out what it is I needed to do. All I needed to do apparently was use Input.GetAxis and use the Horizontal and Vertical Axes. I just needed to go into the Project Setting > Input and edit the positive and negative alternate buttons to null. Here is my ending code as a result.
csharp** **using System.Collections.Generic;[/B] [B]using UnityEngine;[/B] [B][/B] [B]public class PlayerController : MonoBehaviour [/B] [B][/B] [B] //Public Variables\\[/B] [B][/B] [B] public float speed;[/B] [B][/B] [B] //Private Variables\\[/B] [B][/B] [B] private Rigidbody rb;[/B] [B][/B] [B] //Initiate at first frame of game\\[/B] [B][/B] [B] void Start ()[/B] [B] [/B] [B] //Calling Components\\[/B] [B][/B] [B] rb = GetComponent ();[/B] [B] [/B] [B][/B] [B] //Initiate at a set time\\[/B] [B][/B] [B] void FixedUpdate ()[/B] [B] [/B] [B] //Movement Controls\\[/B] [B][/B] [B] float moveHorizontal = Input.GetAxis ("Horizontal");[/B] [B] float moveVertical = Input.GetAxis ("Vertical");[/B] [B][/B] [B] Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);[/B] [B][/B] [B] rb.AddForce (movement * speed);[/B] [B] [/B] [B][/B] [B] //Pick-up Collision\\[/B] [B][/B] [B] void OnTriggerEnter (Collider other)[/B] [B] [/B] [B] if (other.gameObject.CompareTag ("Pick Up"))[/B] [B] [/B] [B] other.gameObject.SetActive (false);[/B] [B] [/B] [B] [/B] [B]** **
If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.
Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.
Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.
Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.
The Character Controller is mainly used for third-person or first-person player control that does not make use of RigidbodyA component that allows a GameObject to be affected by simulated gravity and other forces. More info
See in Glossary physics.
If you want to push Rigidbodies or objects with the Character Controller, you can apply forces to any object that it collides with via the OnControllerColliderHit() function through scripting.
The Skin Width is one of the most critical properties to get right when tuning your Character Controller.If your character gets stuck it is most likely because your Skin Width is too small. The Skin Width will let objects slightly penetrate the Controller but it removes jitter and prevents it from getting stuck.
Hi - wonder if anyone can help.
When we set up 2 player mode for MK8, one of the controllers needs to press and hold X to move forwards, and the other doesn't. If you wait for a race to start, and don't touch either controller, one of the karts sets off and the other sits on the starting grid. Can't find anywhere to change settings or investigate. I'd have expected both to be the same - and maybe for one of the top buttons (when joy con held sideways) to be the GO button? Thanks in advance.
3a8082e126