https://drive . Google . com/file/d/1 UC 2s ys 7 zfd 686 ukqlyamedzkefehzcar/view?usp =共享
正如你在视频中看到的那样,当我试图从山上跳下来时,玩家只是穿过地形,好像没有地形一样,但我仍然可以正常移动。我注意到,每当我离开地面时快速移动时,问题就出现了,就像我第一次开始这个关卡时,我跳得很慢,然后返回地面,每当我跳得快,朝地狱方向移动时,就会出现问题,所以我增加了重力,使我在跳跃时无法移动,但如果我在空中快速移动,玩家不会与地形碰撞,但当我在地面上正常或快速移动时,没有人能帮助我吗?
我在网上搜索了一下,没有找到任何与此相关的东西。
地形1属性:
https://drive . Google . com/file/d/1 vwelecesljfd 7 usep 6 lmq 0kg-3 pwg 67/view?usp =共享
地形2属性:
https://drive.google.com/file/d/1ZH-cIBXlhBMPbmkgZXkQmjt-QVpe6MLu/view?usp=sharing
播放器属性:https://drive . Google . com/file/d/1 VTP 3 tsuidcym 3 orwhy 5 x3kw 6 wwbmwnce/view?usp =共享
以下是用于此目的的代码:
鼠标锁:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class mouselock : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
}
玩家移动:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class playermove2 : MonoBehaviour
{
[Header("movement")]
private float movespeed = 10f;
[SerializeField] float airmultiplier = 0.4f;
[SerializeField] Transform oriantation;
private float horizontalmovement;
private float verticalmovement;
private float rbdrag = 6f;
private Vector3 movedirection;
public float movementmultiplier = 10f;
public bool isgrounded;
private float playerhight = 1.8f;
public float jumpforce = 8;
public Rigidbody rb;
public float grounddrag = 6f;
public float aridrag = 2f;
public int number;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
if (number == 11)
{
SceneManager.LoadScene("finish scene2");
}
if (Input.GetKeyDown(KeyCode.LeftShift))
{
movespeed = 25;
}
if (Input.GetKeyUp(KeyCode.LeftShift))
{
movespeed = 20;
}
if (Input.GetKeyDown(KeyCode.Space) && isgrounded)
{
jump();
}
print(isgrounded);
myinput();
controledrag();
}
private void myinput()
{
horizontalmovement = Input.GetAxisRaw("Horizontal");
verticalmovement = Input.GetAxisRaw("Vertical");
movedirection = oriantation.forward * verticalmovement + oriantation.right * horizontalmovement;
}
private void FixedUpdate()
{
moveplayer();
}
void moveplayer()
{
if (isgrounded)
{
rb.AddForce(movedirection.normalized * movespeed * movementmultiplier, ForceMode.Acceleration);
}
else
{
rb.AddForce(movedirection.normalized * movespeed * movementmultiplier * airmultiplier, ForceMode.Acceleration);
}
}
void controledrag()
{
if (isgrounded)
{
rb.drag = grounddrag;
}
else
{
rb.drag = aridrag;
}
}
void jump()
{
rb.AddForce(transform.up * jumpforce, ForceMode.Impulse);
}
}
冲突:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class collisions2 : MonoBehaviour
{
public playermove2 player;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnCollisionEnter(Collision other)
{
if (other.gameObject.layer == 6)
{
player.isgrounded = true;
}
}
private void OnCollisionExit(Collision other)
{
if (other.gameObject.layer == 6)
{
player.isgrounded = false;
}
}
}
相机移动:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveCamera : MonoBehaviour
{
[SerializeField] Transform cameraposition;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.position = cameraposition.position;
}
}
球员外观:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerlook : MonoBehaviour
{
[SerializeField] private float sensX;
[SerializeField] private float sensY;
[SerializeField] Transform cam;
[SerializeField] Transform oriantation;
private float mouseX;
private float mouseY;
private float multiplier = 0.01f;
private float xRotation;
private float yRotation;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void Update()
{
mouseX = Input.GetAxisRaw("Mouse X");
mouseY = Input.GetAxisRaw("Mouse Y");
yRotation += mouseX * sensX * multiplier;
xRotation -= mouseY * sensY * multiplier;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
cam.transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
oriantation.transform.rotation = Quaternion.Euler( 0, yRotation, 0);
}
}
triggers:
using UnityEngine;
using UnityEngine.SceneManagement;
public class triggers2 : MonoBehaviour
{
public playermove2 playerMove;
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.layer == 8)
{
Destroy(other.gameObject);
playerMove.number++;
}
}
}
得分和高分:
using UnityEngine;
using UnityEngine.UI;
public class scoreandhighscore2 : MonoBehaviour
{
public Text highscoretext;
public Text scoretext;
public playermove2 playermove;
// Start is called before the first frame update
void Start()
{
highscoretext.text = "high score: " + PlayerPrefs.GetInt("highscore");
}
// Update is called once per frame
void Update()
{
scoretext.text = "score: " + playermove.number.ToString();
}
private void FixedUpdate()
{
if ( playermove.number > PlayerPrefs.GetInt("highscore"))
{
PlayerPrefs.SetInt("highscore", playermove.number);
}
}
}
所以我解决了这个问题,解决方案只是将碰撞检测转换为连续的,这样玩家就不会突破地形,我希望这对其他人有所帮助
下面是我做的图片:https://drive . Google . com/file/d/1 ATI 8 xqfqxwqag 8 ejnmzzrs 8d 05 hgu jls/view?usp =共享
问题内容: 我正在制作类似于Doodle Jump的游戏,以使您的玩家尽可能高。现在,我让播放器工作并移动。但是,问题是,我没有重力,或者没有什么会使玩家再次跌倒在地。你们有这样做的想法吗?我试图让玩家一直受到持续的压力,但始终不被压下,但它并不流畅,而且也不像真正的摔倒。在制作这种降低播放器的系统方面,我可以寻求帮助吗? 编辑: 我做到了,但没有成功,却将我的玩家高高举起。 问题答案: 在现实世
我试图在pygame中创建一个下降效果,但我被困在一个特定的问题上。每当玩家摔倒并与平台发生碰撞时,我的玩家类就会开始上下摆动。我确信这与我的更新循环有关,但我不确定它到底是什么。我尝试了几种方法,例如重新排列层次结构,但无济于事。我最终在网上搜索,但没有得到答案。所以如果有人能帮忙,我将不胜感激。 谢谢!
金币掉落效果。 开发者说:有粒子效果,但是顶点释放方面存在内存泄漏,望高手教之。 [Code4App.com]
在我的《我的世界》多人服务器上,我有一个名为《毁灭》的游戏。在那里,目标是在插件中编码的几次自然灾害中幸存下来。 我使用插件来处理不同灾难中的块管理。 如果可能的话,我用异步任务制作了其他东西。 现在我的问题是,即使有两个玩家玩它,他们也落后于世界。 (世界是一个自定义构建的地图150x150块)TPS在刻度上几乎是恒定的,RAM的使用也不会过度使用。 有人知道为什么它仍然落后于玩家的视野吗?
为什么我的保安(S)和唐纳德(D)处于相同的位置。 地图应该是这样打印出来的 [D----] [- - - - -] [- - - - -] [--S-] [--P--] 但它却像这样出现 [S----] [- - - - -] [- - - - -] [- - - - -] [--P--] 所以正如你在这里看到的,我把安全位置设为[3,2],但出于某种原因,它没有将其识别为[3,2],并将安全位
我正在做一个2D平台,只是增加了重力 然而,如果空格键在玩家完成跳跃后仍然被按住,玩家就会在半空中继续跳跃。 我知道我需要检查球员是否真的在地面上,但当我这样做时,它总是返回“false”,如我的跳跃方法所述: